Declaring a boolean in JavaScript using just var

后端 未结 8 1545
余生分开走
余生分开走 2020-12-23 02:54

If I declare a JavaScript boolean variable like this:

var IsLoggedIn;

And then initialize it with either true or 1

8条回答
  •  生来不讨喜
    2020-12-23 03:22

    The variable will become what ever type you assign it. Initially it is undefined. If you assign it 'true' it will become a string, if you assign it true it will become a boolean, if you assign it 1 it will become a number. Subsequent assignments may change the type of the variable later.

提交回复
热议问题