JavaScript authoritative guide-data type notes

Source: Internet
Author: User

Original value and applied value

1. Original value type Data room immutable (change original value type data, return a new object)

var str0 = ' Test ';    var str1 = str.replace (' t ', ' a '); alert (STR1);   // output ' AEST 'alert (STR0); // output ' test '       

2. The application value type is variable (his value can be modified)

Object Direct Amount var o = {x:1, y:2, Z:3};console.log (o);     // Output Object {x=1, y=2, z=3}o.z = 4// Output Object {x=1, y=2, z=4}// Array Direct amount var arr = [1, 2, 3 // output [1,2,3]arr[2] = 4/ output [1, 2,4]           
Several knowledge points 1.javascript is the implementation of ECMAScript, and its components are:

2. Original type and reference type (the explanation of W3school is clear)

Raw values: Simple data segments stored in stacks (stack), that is, their values are stored directly in the location where the variable is accessed.

Reference value: The object stored in the heap (heap), that is, the value stored at the variable is a pointer (point) to the memory of the storage object.

  

(* in many languages, strings are treated as reference types, not primitive types, because the length of the string is variable.) ECMAScript has broken this tradition. )

3.javascript Variable declaration and scope

1). js in the variable declaration has the following several (divided into the use of the keyword VAR, not the use of the keyword Var)

//------------------------------------------//
//declare separately with VARVar A; var b; a = ' Hello ' ; b = ' World ' ; var A, B;// single var declares and assigns var a = 1, b = 2------------------------------------------//// do not use var to declare g = ' test '; //

2). The scope of variables in JS is divided into global scope () and local scope (composed of function functions) two kinds

  

(* * When the JS engine executes, each entry to a scope (environment), according to the current context, creates a context object for that environment, at this stage, the Variableobject object, scope chain, and this point to the object will be determined recommended reading)

4. Object comparisons, even if two objects contain the same attributes and the same values, they are not equal (two arrays are not equal for each index exactly equal)

Object comparisons are reference comparisons, and are equal only if they refer to the same object

(This is similar to the fact that the name is the same as the age but not the same person, but if the person has a nickname (other references) then the nickname and his name all refer to him alone)

var O1 = {name: ' Zhang ', age:23};console.log (O1);    // Output Object {x=1,  Y=1}var O2 = {name: ' Zhang ', age:23};console.log (O1);       // Output Object {x=1, Y=1}// output falsevar O3 = O1;console.log (O3); // Output Object {x=1, Y=1}// output True                  

JavaScript authoritative guide-data type notes

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.