"JavaScript" Quick Start

Source: Internet
Author: User
Tags delete key iterable ming hasownproperty

Excerpt address Quick Start

NO1:

JavaScript is strictly case sensitive

No2:

JavaScript does not distinguish between integers and floating-point numbers, and is uniformly represented by number

Nan means not a number, which is represented by Nan when the result cannot be evaluated

Infinity is infinitely large, and is represented as infinity when the value exceeds the maximum value that JavaScript can represent.

JavaScript allows comparison of arbitrary data types

No3:

Pay special attention to the equality operator == . At design time, JavaScript has two comparison operators:

The first is the == comparison, which automatically converts the data type to compare, and many times it gets very weird results;

The second is the === comparison, which does not automatically convert the data type if the data type is inconsistent, returns false if consistent, and then compares.

Because of this design flaw in JavaScript, do not use == comparisons, always insist on using === comparisons.

Another exception is that NaN this particular number is not equal to all other values, including its own

No4:

undefined, which represents "undefined."

NO5:

In different JavaScript files on the same page, if you do not have var to declare it, the variables i will be used, causing i the variables to interact with each other, resulting in hard-to-debug error results.

A var variable that uses a declaration is not a global variable, its scope is limited to the body of the function in which the variable is declared (the concept of the function will be explained later), and the variable of the same name does not conflict with each other in the function body

Variables that are not var declared are considered global variables, and in order to avoid this flaw, all JavaScript code should use the strict pattern. JavaScript code that runs in strict mode, which is enforced by var declaring variables that are var used without declaring variables, will result in run errors.

NO6:

Because multiline strings are more \n cumbersome to write, the newest ES6 standard adds a multiline string representation, using the anti-quote ' ... ' expression. Reverse quotation marks on the left side of the number key 1 below the ESC of the keyboard

No7:

Template string

var name = ' Xiao Ming '; var age =; var message = ' Hello, ${name}, you ${age} year old! '; alert (message);

No8:

The string is immutable, and if you assign a value to an index of a string, there is no error, but there is no effect:

No9:

Array length Assigning a new value directly to it will result Array in a change in size:

var arr = [1, 2, 3//  3arr.length = 6//  arr becomes [1, 2, 3, Undefined, Undefined, undefined]arr.length = 2//  arr becomes [1, 2]
var arr = [' A ', ' B ', ' C '];arr[1] =//  arr now changes to [' A ', ' a ', ' C ']
var arr = [1, 2, 3];arr[5] = ' x '//  arr becomes [1, 2, 3, Undefined, undefined, ' x ']

No10:

"Slice" intercept

var arr = [' A ', ' B ', ' C ', ' D ', ' E ', ' F ', ' G '];arr.slice (//  starting at index 0, to index 3 end, but not including index 3: [' A ', ' B ' , ' C ']//  starting from index 3 to end: [' D ', ' E ', ' F ', ' G ']
var arr = [' A ', ' B ', ' C ', ' D ', ' E ', ' F ', ' G ']; var acopy =//  [' A ', ' B ', ' C ', ' D ', ' E ', ' F ', ' G ']//  false

Arrayadd several elements to the end of "push"

The last element of the "pop" Array is erased.

Arrayadd several elements to the head of "Unshift"

"Shift" Array Delete the first element

"Splice" modifies the array

vararr = [' Microsoft ', ' Apple ', ' Yahoo ', ' AOL ', ' Excite ', ' Oracle '];//Delete the 3 elements starting at index 2, and then add the two elements:Arr.splice (2, 3, ' Google ', ' Facebook ');//return deleted elements [' Yahoo ', ' AOL ', ' Excite ']Arr//[' Microsoft ', ' Apple ', ' Google ', ' Facebook ', ' Oracle ']//Delete only, do not add:Arr.splice (2, 2);//[' Google ', ' Facebook ']Arr//[' Microsoft ', ' Apple ', ' Oracle ']//add only, do not delete:Arr.splice (2, 0, ' Google ', ' Facebook ');//return [] because no elements were removedArr//[' Microsoft ', ' Apple ', ' Google ', ' Facebook ', ' Oracle ']

"Concat" connects the current Array and the other Array , and returns a newArray

var arr = [' A ', ' B ', ' C ']; var added = Arr.concat ([1, 2, 3//  [' A ', ' B ', ' C ', 1, 2, 3]//  [' A ', ' B ', ' C ']

"Join" Array connects each current element with the specified string and returns the concatenated string.

Ar arr = [' A ', ' B ', ' C ', 1, 2, 3];arr.join (//  ' a-b-c-1-2-3 ' )

NO11:

Object

var xiaoming = {    ' xiaoming ',    1990,    ' Middle School ',    1.70,    n/    A,null};

Access

// ' Xiao Ming ' // 1990

Or

var xiaohong = {    ' Little Red ',    ' middle-school ': ' Middle School '};

Access

// ' The Middle School ' // ' Little Red ' // ' Little Red '
varXiaoming ={name:' Xiao Ming '};xiaoming.age; //undefinedXiaoming.age = 18;//Add an Age propertyXiaoming.age;// -DeleteXiaoming.age;//Delete Age PropertyXiaoming.age;//undefinedDeletexiaoming[' name '];//Remove the Name propertyXiaoming.name;//undefinedDeleteXiaoming.school;//Deleting a non-existent school property will not error

"In"

var xiaoming = {    ' xiaoming ',    1990,    ' Middle School ',     1.70,    n/    A,null}; inch // true inch // false

To determine whether a property is xiaoming owned by itself, but not inherited, you can use the hasOwnProperty() method:

var xiaoming = {    ' xiaoming '};xiaoming.hasownproperty (//  true// false

No12:

JavaScript treats,, null undefined 0 , NaN and empty strings ‘‘ as false other values are consideredtrue

NO13:

Cycle

var x = 0; var i;  for (I=1; i<=10000; i++) {    = x +

Note: do not write int i=1 in parentheses, because JS is a dynamic language and does not need to define variable types

"For...in"

var o = {    ' Jack    ',    ' Beijing '};  for (var in o) {    if  (O.hasownproperty (key)) {        //  ' name ', ' age ', ' City '     }

NO14:

"Map"

 var  m = new  Map ([[' Michael ', page], [' Bob ', ['], [' Tracy ', 85 ' Michael '); //   
var New // Empty Map // Add new Key-valuem.set (' Bob ', '); M.has (//  existence of key ' Adam ': true//  67 M.Delete/  Delete key ' Adam '//  undefined

"Set"

var New Set ([1, 2, 3, 3, ' 3 '//  set {1, 2, 3, "3"}
S.add (4//  set {1, 2, 3, 4}s.add (4//  is still set {1, 2, 3, 4}

NO15:

"Iterable"

Array, Map and Set all belong to the iterable type.

"For...of ..."

varA = [' A ', ' B ', ' C '];vars =NewSet ([' A ', ' B ', ' C ']);varm =NewMap ([[1, ' X '], [2, ' Y '], [3, ' Z ']]); for(varX of a) {//Traversal ArrayConsole.log (x);} for(varX of s) {//traversing setConsole.log (x);} for(varX of M) {//Traverse MapConsole.log (x[0] + ' = ' + x[1]);}

for ... offor ... inthe difference between loops and loops:

1. for ... in loops because of historical problems, it iterates over the object's property name.

2. for ... of loops completely fix these problems, it only loops the elements of the collection itself

NO16:

"ForEach ()"

var New Set ([' A ', ' B ', ' C ']); S.foreach (function  (element, sameelement, set) {    Console.log (Element) ;});
var New Map ([[1, ' X '], [2, ' Y '], [3, ' Z ']]); M.foreach (function  (value, key, map) {    Console.log ( value);});
var a = [' A ', ' B ', ' C '];a.foreach (  Element) {    Console.log (element );});

"JavaScript" Quick Start

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.