Basic Content of javascipt-details to be aware of _ basic knowledge

Source: Internet
Author: User
In this article, I will introduce you to the basic content of javascipt-the details you need to pay attention to. If you need it, please refer to it. Javascip-basic--- Notes for details:

1. Special values: NaN, Infinity, isNaN (), isFinite ()

NaN:

The Code is as follows:


Var a = parseInt ('a123 ');
Window. alert (a); // output NaN

Infinity:

The Code is as follows:


Window. alert (6/0); // output Infinity (it is better not to write this)

IsNaN (): determines whether it is a number. If it is not a number, true is returned. If it is a number, false is returned.

The Code is as follows:


Var a = "dd ";
Window. alert (isNaN (a); // return true

IsFinite (): used to determine whether it is infinite. If number is NaN (not a number) or positive or negative infinity, false is returned.

The Code is as follows:


Window. alert (isFinite (6/1); // return true
Window. alert (isFinite (6/0); // return false

2. logical operators:

In logical operations, 0, "", false, null, undefined, and NaN indicate false.

(Or |) | returns the first value (the object can also be) other than false, or the last value (if all values are false)

This knowledge point is widely used in javascript frameworks.

A,

The Code is as follows:


Var a = true;
Var B = false;
Var c = B |;

Window. alert (c); // Output true

B,

The Code is as follows:


Var a = 2;
Var B = 0
Var c = a | B;

Window. alert (c); // returns the first value and outputs 2

C,

The Code is as follows:


Var a = false;
Var B = "";
Var c = 0;
Var d = new Object (); // Object

Var aa = a | B | c | d; // a, B, and c are all false.
Window. alert (aa); // return d (object)

4. multi-branch switch

The Code is as follows:


Var flag = 1;

Switch (flag ){

Default:
Window. alert ("nothing ");

Case 'A ':
Window. alert ("");

Case 'B ':
Window. alert ("B"); // if no break statement exists and no matching is successful, all results are output.

}

The Code is as follows:


Var flag = 1;

Switch (flag ){

Default:
Window. alert ("nothing ");

Case 'A ':
Window. alert ("");

Case 1:
Window. alert ("B"); // No break statement. If the match is successful, the break statement is no longer found. At this time, B is output.

}

5. function call

Func. js

The Code is as follows:


Function abc (val ){

Window. alert ("abc ()" + val );
}

// Functions with returned values
Function test (num1, num2 ){

Var res = 0;
Res = num1 + num2;

Return res;
}

// Functions without return values
Function noVal (num1, num2 ){

Var res = 0;
Res = num1 + num2;
}

Function call:

The Code is as follows:





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.