Editor Arrow Download Open
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>JavaScript const example</title> </head> <body> <script> const a = 10; console.log("Constant a: ", a); // a value 10 const b; // weird, const can define without initial value, console.log("Constant b: ", b); // automatic assign 'undefined' //const a = 20; // throw TypeError 'a' already been declared //var a = 20; // throw TypeError 'a' already been declared // 'a' is already used as a constant can not declare as a variable a = 20; // Define 'a' variable without var keyword, can't throw error console.log("a without var:", a); const c = 20; // Define and initializing 'c' constant variable const d = b; // Define 'd' constant variable, initialize constant 'c' console.log("Constant c: ", c); console.log("Constant d: ", d); const obj = {"a": "A", "b": "B"}; // Define and initializing constant object console.log("Constant Object:", obj); console.log("Constant obj.a:", obj.a); //var obj = 10; // throw TypeError 'obj' already been declared obj.a = "AA"; // 'a' key, try to reassign console.log("Reassign after Object:", obj); // Object {a: "AA", b: "B"} </script> </body> </html>
  Preview Arrow