Logical judgment of JavaScript and the knowledge point of the loop

Source: Internet
Author: User

Boolean number
number:0,1.2,0377 octal. 0xFF binary Infinity Infinity (10/0), exponential (scientific notation)
Infinity * 0==nan
Infinity + Infinity = Infinity
infinity-infinity = Infinity;
-infinity + Infinity = Infinity;
Infinity *10 = Infinity;
A few important ways
--parseint/parsefloat/tofixed () returns the number
The method of judging whether it is a number: IsNaN, if the number (string number) is False
Alert (IsNaN (document.getElementById ("text"). value));
parseint ("12SDFSD");//12
When rejecting PX: parseint ("10px") ==10
var boxdom = document.getElementById ("box");
var width =parseint (boxDom.style.width);//100
var height =parseint (boxDom.style.height);//100

ToFixed applies To: When a progress bar intercepts decimals, rounding


boolean--condition judgment if ElseIf else
Falsy:
var flag;//0 number null undefined "" False all False (false)
For example: var text = document.getElementById ("T"). Value;
if (!text) {alert ("Please enter a value and get Focus"); return;}
var a = "100";
if (a) ==a=true
var a = "0";
if (a) a= true; Because the value of the element obtained from the form form is a string, if you do not understand it, use TypeOf to print the data type as much as possible. In the development phase try not to understand the multi-debug and alert
Often in the process of debugging we, we write a lot of logic when we can use the Return key organization code to execute down until the debug succeeds in the return to clear out.
Logical judgment: or (| |) and (&&) non (!)
Non, True and False, False also true for example:!false = TRUE//!true= false;
Or: One is good (true), all are good, return all are bad people are bad people such as: true | | False | | True ==true
And: A bad guy is all bad guys. False && true && true, Result: false. Return True&&true&&true =true

Often in development, it is often enclosed in parentheses to execute your own business logic, which is a priority
For example: true | | (True && false) ==true
true | | True ==true


Note Dot: + is the connection character Doom
For example: var a = 10; var B = "Ten"; var C = a+parseint (b);//20
Note: Eval has the ability to compute,

Logical judgment of JavaScript and the knowledge point of the loop

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.