// var
// Declares a variable, optionally initializing it to a value.
// let
// Declares a block-scoped, local variable, optionally initializing it to a value.
// const
// Declares a block-scoped, read-only named constant.
/* Var-let-const Examples*/
/*
var a;
console.log('The value of a is ' + a);
// The value of a is undefined
console.log('The value of b is ' + b);
// The value of b is undefined
var b;
// This one may puzzle you until you read 'Variable hoisting' below
console.log('The value of c is ' + c); // Uncaught ReferenceError: c is not defined
let x;
console.log('The value of x is ' + x); // The value of x is undefined
console.log('The value of y is ' + y); // Uncaught ReferenceError: y is not defined
let y;
*/
/*
console.log(x === undefined); // true
var x = 3;
var myvar = 'my value';
(function() {
console.log(myvar); // undefined
var myvar = 'local value';
})();
*/
/*
// Using a string method doesn't mutate the string
var bar = "baz";
console.log(bar); // baz
bar.toUpperCase();
console.log(bar); // baz
// Using an array method mutates the array
var foo = [];
console.log(foo); // []
foo.push("plugh");
console.log(foo); // ["plugh"]
// Assignment gives the primitive a new (not a mutated) value
bar = bar.toUpperCase(); // BAZ
console.log(bar);
let myListL = ['home','school', , ,];
let myListM = ['home' , , ,'school'];
let myListR = [ , , ,'home','school'];
console.log(myListL,myListM,myListR)
*/
function Person() {
// The Person() constructor defines `this` as itself.
this.age = 0;
setInterval(function growUp() {
// In nonstrict mode, the growUp() function defines `this`
// as the global object, which is different from the `this`
// defined by the Person() constructor.
console.log(this.age);
this.age++;
}, 1000);
}
var p = new Person();