Learn some of the memory things of JavaScript

Source: Internet
Author: User

1. Variables

Define variables using the var keyword,

function Test () {    var   'one';      } Test (); alert (cc);              // error not defined variable If you  remove Var, it will pop up 11 ... This example can explain the use of global variables and local variables.

2. Data type: Undefined,null,boolean,number, and string. There are also 1 of complex object,js that do not support any mechanism for creating custom types

Undefind and null are data types with only one value, and from a logical point of view, a null value represents an empty object pointer, which is why using the TypeOf operator to detect that a null value returns an object, if a variable is defined to be stored in the future. It is a good idea to initialize the variable to null instead of the other value, so that if you check the value of NULL, you know whether the corresponding variable has saved a reference to an object: for example:

var car=null; if (Car! =null)   {// This side can do some work  on the car's objects }

In fact, undefined refers to the derivation of a null value, so ECMA-262 specifies that the test of equality to them returns true;

Alert (Null = = undefined)//result returns true;

The Boolean type is the most used type in ECMAScript, which has only true and false, which is not the same as a numeric value, so true is not necessarily equal to 1, and false is not necessarily equal to 0, and true and false are identifiers, Not a Boolean value, case sensitive

All types of values can be converted to a Boolean value, call the Transform function Boolean (), as to whether the return is true or false, depending on the data type of the converted value and the actual value

Convert the value of the data type                       to True to a                     value of                       false Booleantrue                                    falsestring                          any non-empty string                      "" (empty string)                       number any non-0 value                         0 and Nanobject                         any                               object nullUndefined                    n /a                                     undefined

`

Learn some of the memory things of JavaScript

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.