Declaring vs Initializing a variable?

前端 未结 7 1133
暖寄归人
暖寄归人 2020-12-06 05:48

I\'m curious to know the difference between declaring a variable, and initializing a variable. e.g.

var example; // this is declaring

var example = \"hi\" /         


        
7条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-06 06:36

    Declaring is introduction of a new name in the program.

    var test;        // Is this a declaration ?
    

    Initialization refers to the "assignment" of a value.

    var test = {first:"number_one"}  // Now that object is initialized with value
    

提交回复
热议问题