Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

If I declare a JavaScript boolean variable like this:(如果我声明一个像这样的JavaScript布尔变量:)

var IsLoggedIn; And then initialize it with either true or 1 , is that safe?(然后用true1初始化它,这样安全吗?) Or will initializing it with 1 make the variable a number?(或者用1初始化它使变量成为一个数字?)   ask by mrblah translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
432 views
Welcome To Ask or Share your Answers For Others

1 Answer

Types are dependent to your initialization:(类型取决于您的初始化:)

var IsLoggedIn1 = "true"; //string var IsLoggedIn2 = 1; //integer var IsLoggedIn3 = true; //bool But take a look at this example:(但是看看这个例子:) var IsLoggedIn1 = "true"; //string IsLoggedIn1 = true; //now your variable is a boolean Your variables' type depends on the assigned value in JavaScript.(变量的类型取决于JavaScript中的赋值。)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...