text-javascript.js (1122B)
1 // Taken from https://en.wikipedia.org/wiki/JavaScript 2 3 // Declares a function-scoped variable named `x`, and implicitly assigns the 4 // special value `undefined` to it. Variables without value are automatically 5 // set to undefined. 6 var x; 7 8 // Variables can be manually set to `undefined` like so 9 var x2 = undefined; 10 11 // Declares a block-scoped variable named `y`, and implicitly sets it to 12 // `undefined`. The `let` keyword was introduced in ECMAScript 2015. 13 let y; 14 15 // Declares a block-scoped, un-reassignable variable named `z`, and sets it to 16 // a string literal. The `const` keyword was also introduced in ECMAScript 2015, 17 // and must be explicitly assigned to. 18 19 // The keyword `const` means constant, hence the variable cannot be reassigned 20 // as the value is `constant`. 21 const z = "this value cannot be reassigned!"; 22 23 // Declares a variable named `myNumber`, and assigns a number literal (the value 24 // `2`) to it. 25 let myNumber = 2; 26 27 // Reassigns `myNumber`, setting it to a string literal (the value `"foo"`). 28 // JavaScript is a dynamically-typed language, so this is legal. 29 myNumber = "foo"; 30 31 const target = "foo";