Variables
The very basics of JavaScript: How to save something inside a little token contained called a "variable"!
Variables
// the "var" keyword is not really used anymore, but you'll still see it in older
// code. It's suggested not to use it anymore. Use let instead!
var myVariableName = "This is a string value";
// The "let" keyword defines a variable where the value and type can be changed later.
let myOtherVariable = "We can change this later";
// If you're going to define the actual value later, you can simply declare it
// without giving it a value
let changeMeLater;
// We can change the content of an existing variable by omitting the "let" keyword.
changeMeLater = "Oh cool I have a value now!"
// The "const" keyword defines a variable that can't change type but, in the case
// of objects and arrays (see "Data Types" below) can be modified. You'll see this
// better in context later on.
const actuallyConstant = "I cannot be modified";
actuallyConstant = "This will fail";
const notReallyConstant = { blah : "foo" };
notReallyConstant.blah = "meh";
notReallyConstant.thing = "thing2";Last updated