DEV Community

Cover image for let var const - variables in js
Manikandan K
Manikandan K

Posted on • Updated on


let var const - variables in js


  • variables are lable that references a value.
  • variables are used to store information to be reference and manipulated in a computer program.
  • variables holds information/data.
  • storing information.
let name = 'Manikandan';
    let        -> start with  //(let, var, const)
    name       -> variable identifier
    Manikandan -> information/data
    ;          -> end of the statement

Enter fullscreen mode Exit fullscreen mode


  • var is function-scope.

Image description

  • Variables defined with 'var', redeclare and reassign is possible.

Image description

Image description


  • let is block-scope

  • Some lines of code will written in { } these parentheses, it

  • is called block-scope.

  • block-scope Variable cannot be access outside the block.

Image description

  • Variables defined with 'let', must be declare before use/assign value.
  • Once declare a Variable with 'let', after re-assign is possible but redeclare is impossible.

Image description


  • const is block-scope.
  • variable define with 'const', cannot be redeclare and cannot be reassign.

Image description

Top comments (0)


11 Tips That Make You a Better Typescript Programmer

1 Think in {Set}

Type is an everyday concept to programmers, but it’s surprisingly difficult to define it succinctly. I find it helpful to use Set as a conceptual model instead.

#2 Understand declared type and narrowed type

One extremely powerful typescript feature is automatic type narrowing based on control flow. This means a variable has two types associated with it at any specific point of code location: a declaration type and a narrowed type.

#3 Use discriminated union instead of optional fields


Read the whole post now!