Wednesday, 21 September 2022

ES6 Variables

 Block scope -  Block scoping means declaring a variable, not just inside a function, but around any curly brackets like if statements or loops.

Var      outside of a function, it belongs to the global scope.

     inside of a function, it belongs to that function.

inside of a block like loop etc, still avail outside the block


  let     it block scoped


const       once it is created, it cant be changed.  it is block scoped
               it defines constant reference value



Because of this you can NOT:

👉Reassign a constant value
👉Reassign a constant array
👉Reassign a constant object


But you CAN:

👉Change the elements of constant array
👉Change the properties of constant object

No comments:

Post a Comment

ES6 Variables

  Block scope -  Block scoping means declaring a variable, not just inside a function, but around any curly brackets like if statements or ...