published: 2nd of November 2021
Like most languages, variables in Javascript are defined with the = operator.
There are 3 different keywords that can be used to define a variable.
// var syntax (considered depricated)
var name = "stuff";
// let syntax
// initialize variable without value assignment
// only available with "let" keyword
let name;
// initialize a variable and assign a value
let name = "stuff";
// re-assign a variable
let name = "things";
// const syntax
// initialize a constant and assign a value
// a value must be assigned when initialized
const name = "stuff";
// re-assigning a constant will result in a runtime error
const name = "things"; // => Uncaught SyntaxError: redeclaration of var name