JavaScript basic Commands

Source: Internet
Author: User

var myName = "Willy Jane"; Statement 1

var is the keyword in JS, variable. The above statement means: Define declares a myname variable and assigns MyName Willy Jane.

var myName = "Willy" + "Jane"; Statement 2

Statement 1 is consistent with the result of statement 2, but there is a "+" sign in statement 2, which is a connection string.

var variables can store string, array, null, Integer, Undefined, and so on data types.

var array=[1,3,5];    var null= ""; var number = 2.4;

JS. The use of the push () method:. Push () pushes one or more parameters into the end of the array.

var arr=[1,3,5,];

Arr.push (4,7,8); The value for arr now is [1,3,5,4,7,8]

Arr.push ([2,3]); The value for arr now is [1,3,5,4,7,8,[2,3]]

JS. The use of the pop () method: Used to "throw" a value at the end of an array. Any type of entry in the array (numeric, string, or even array) can be "thrown".

var array1=[3,4,6,7].pop (); Now that the value of Array1 is 7, the array becomes [3,4,6].

JS. The use of the shift () method: Removes the first element.
var array1=[3,4,6,7].shift (); Now that the value of Array1 is 3, the array becomes [4,6,7].

JS. The use of the . Unshift () method: Adds an element to the head of the array.

var array1=[3,4,6,7].unshift (12); Now that the value of Array1 is 12, the array becomes [12,3,4,6,7].

Construction of JS function: functionkeyword + functions name + (parameter (formal parameter), parameter (parameters)) + curly brace {} parameters

function MyFunction () {

Console.log ("Hi World");
}
MyFunction (); Call the MyFunction () function. Show Hi World on the console.

JS in the global variables and local variables . Their scope is different, when the scope of global variables and local variables intersect, that is, local and global have the same variable name, in the local priority call.

var Mygorbel = "CATS";

function MyFunction () {

var mygorbel= "Dogs";

var retu= mygorbel;

return retu;

}

Boolean Boolean True or False in conjunction with the IF statement

function test (mycondition) {
if (mycondition) {
Return "It was true";
}
Return "It was false";
}
Test (TRUE); Returns "It was true"
Test (FALSE); Returns "It was false"

Boolean Boolean vs. Comparison method

function Equalitytest (myval) {
if (Myval = = 10) {
return "Equal";
}
Return "Not Equal";
}

The difference between congruent and equality in JS: Congruent ( === ) is an operator relative to the == equality operator (). Unlike the equality operator, it is strictly congruent, and it compares the value of the element with the same 数据类型 .

JS in the difference between the non-congruent and unequal:

1! = 2//True
1! = "1"//False
1! = ' 1 '//False
1! = TRUE//False
0! = false//False

3!== 3//False
3!== ' 3 '//True
4!== 3//True

5 > 3//True
7 > ' 3 '//True
2 > 3//False
' 1 ' > 9//False

6 >= 6//True
7 >= ' 3 '//True
2 >= 3//False
' 7 ' >= 9//False

Switch statement

Switch (num) {
Case Value1:statement1;
Break
Case Value2:statement2;
Break
...
Case VALUEN:STATEMENTN;
Break
}

JavaScript basic Commands

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.