开发者

"initiating a variable" in Javascript: what does it mean?

开发者 https://www.devze.com 2023-02-09 11:30 出处:网络
I am learning now JS but get so often this co开发者_开发百科ncept of \"initiating a variable\". Could anyone give me a good answer? Cheersvar name = \'john\'; is declaring a variable and assigning the

I am learning now JS but get so often this co开发者_开发百科ncept of "initiating a variable". Could anyone give me a good answer? Cheers


var name = 'john'; is declaring a variable and assigning the value 'john' to it, aka initializing it.


Simply means giving it a value so it's ready to use.

It's the next step from simply "declaring a variable" which you'll see in languages such as C, C#, Java, etc., which is more "making a variable ready to use, but leaving it 'empty' for now".


declaring a variable with var makes it local to the function it's in. Otherwise it could be available in other functions which can be confusing if you use the same variable name in other functions without declaring them with var...

0

精彩评论

暂无评论...
验证码 换一张
取 消