Variable and Parameter

Keyword
Scope
IsMutable

var

function

yes

let

block

yes

const

block

no

if (true) {
    let a = 40;
    console.log(a); // 40
}
console.log(a);     // undefined.
let a = 50; let b = 100;
if (true) {
    let a = 60;
    var c = 10;
    console.log(a/c);         // 6
    console.log(b/c);         // 10
}
console.log(c);                 // 10
console.log(a);                 // 50

Destructuring

Destructuring Arrays

Destructuring Objects

default parameters

Rest Parameter (is like varargs)

  • Rest parameter allows the functions to accept an indefinite number of arguments as as array.

  • Rest parameter should appear after any regular parameters.

Spread Parameter

  • Spread parameter is the exact opposite of how Rest parameter works.

  • It allows a function to take an array as as argument and then spread out its elements so that they can be assigned to individual parameters.

Template Literals

  • JavaScript always hoists the declaration of any variable at the top so even if in code it appears to be after calling the variable it won't give an error.

Last updated

Was this helpful?