JavaScript Foundation Focus

Source: Internet
Author: User

It's been a long time to touch JavaScript, but it's never been a systematic way to learn the language. Take advantage of the fact that you have just graduated and some of the reasons for not working on the system to understand the language, but also want to develop the habit of blogging in such a language, because I think this is a very sacred and honorable to the programmer thing.

1.1 Background

Believe that many beginners are forgotten or confused is the official JavaScript name: ECMAScript. June 17, 2015, ECMAScript 6 released the official version, namely ECMAScript 2015.

  1.2 Syntax

General syntax ellipsis

Emphasis is placed on:

1. Original values and objects: The original values include Boolean values, numbers, strings, null, and undefined. The other values are the objects. The main difference between the two is the way they compare: Each object has a unique identity and only equals itself.

var obj1={}; var obj2== = = obj2); // false alert (obj1= = =obj1); // true var prim1=123; var prim2=123; alert (prim1= = =prim2); // true

2. Use typeof and instanceof to classify values.

typeof
Number of operands Results
Undefined ' Undefined '
Null   Object
Boolean value Boolean
Digital Number
String String
Function function
All other regular values Object
Values created by the engine JS engine can be allowed to create some values, and the result of TypeOf can return any string

3. Boolean value:

False value: Undefined,null,false,-0,nan, "

Binary logical operators: the two-element logical operator in JavaScript is short-circuited . If the first operand is sufficient to determine the result, then the second operand is not evaluated. With (&&): Returns if the first operand is a false value. or (| | ): If the first operand is true, return it.

4.IIFE:

Introduce a new scope. Action: Removes unintentional sharing caused by closures (functions and variables in the surrounding scopes to which it is connected).

Cases:

              

var result=[];  for (var i=0;i<5;i++) {result.push (function() {return i;}); // (1) }console.log (result[1] ());  // 5   (not 1) Console.log (Result[3] ());  // 5   (not 3)

The line that is labeled (1) returns the current value of I, not the value of the function when it was created. At the end of the loop, the value of I is 5, so all functions in the array return this value. If you want to mark (1) This line of functions to get a snapshot of the current I value, you can use Iife.

 for (var i=0;i<5;i++) {  (function  () {    var i2=i;     Result.push (function() {return  i2});            ()) ; }

This is all in the process of the previous not noticed or not learned part of the knowledge, write here to do the knowledge point of the supplement.

     

 

JavaScript Foundation Focus

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.