Thursday, September 17, 2020

variable-declaration

Difference between Var ,Let ,Const



There are 3 types of declarations in ReactJS
  • var
  • let
  • const


var declaration example


var name'cse'

    var is the globally scoped , function/locally scoped.

        The scope is global when the variable is declared outside a function.

        This means that any variable that declared with the var keyword outside a function block is globally scoped.

        var is the function scoped where it declared within the function.

        var can be updated or re-declared.

        var variable which is not declared automatically it takes the value as undefined.

 
let declaration example


let name'cse'


    let is the locally scoped or block scoped. let variable can be live within the curly braces {}.

     let can be updated but not re-declared. 

       where let keyword is not declared or initialized then automatically it takes the value as Reference error.

Const declaration example
        variable declares with the const value it maintains as constant.


  const name'cse'

        
        Like let declaration,const value only be accessed within the block they were declared.
            const value cannot be updated or re-declared.



Thanks for reading :)

No comments:

Post a Comment

variable-declaration

Difference between Var ,Let ,Const There are 3 types of declarations in ReactJS var let const var declaration example var   name =  ...