Basic knowledge of Javascript Boolean analytics

Source: Internet
Author: User
Today, I encountered an interesting problem when I was working on the enterprise level function of Jingdezhen. On a jsp page, I need to convert a java string into a boolean type of js. Originally, I thought that the boolean type conversion of js is the same as that of java. After all, everyone is the same ancestor. below is my writing method.
Function foo (){
Var temp = Boolean. valueOf ('<% = javatelean %> ');
Alert (temp = false );
}
The java variable javatelean is a string with the value "false". I thought it would be true, but the result would be false, which is really depressing.
Just now I checked the javascript authoritative guide, just now I was confused. It turns out to be like this:
If you want to convert other types to Boolean type, you should use Boolean (value), new Boolean (value), Boolean. the valueOf () method is only available to objects and is not a Boolean static method. It is also important that values 0, NaN, null, null, and undefined are converted to false, other original values, except false (but including the string "false"), and other objects and arrays are converted to true.
Here, you should think it's a value to be fooled by js?
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.