Native JavaScript Learning JS variable Comprehensive understanding of the basics

Source: Internet
Author: User
Tags lowercase variable scope

1. Name of variable

Name of method (hump naming method)

All lowercase: All underscores between words and words (my_namespace)

Mixed case: First letter lowercase other words in uppercase.

Rules

First character English letter or underline

Make up an English alphanumeric underline

Taboo JavaScript keyword reserved word

2. Declaration of variables 

Display declaration: var keyword

Bad habits: No type duplicate declaration an implicit declaration does not declare a direct assignment

Positive solution: First declare after read and write first assignment after operation

3. Variable type 

Value type

A The Occupy space is fixed in the stack

B The value itself is saved and assigned

C) using typeof to detect the type of data

D) Basic type data is a value type

Reference type

A the occupied space is not fixed and stored in the heap

B to save and copy is a pointer to the object

C) using instanceof to detect the type of data

D the object constructed using the new () method is a reference type

4. Variable Scope   

Global variables that contain variables defined outside the function body define no var in the function body not recommended (any location can be invoked)

A local variable contains a parameter variable of a variable function declared using var within the body of a function (current function body part)

Scope Chain: Inner function can access outer function local variable

Outer function cannot access inner-layer function local variable

Lifecycle: Global variables exist unless they are displayed or deleted

local variable from declaration to function completed or displayed delete

Recycle mechanism tag Clear reference count

Above the original JavaScript learning JS variable full understanding is a small series to share all the content, hope to give you a reference, but also hope that we support the cloud habitat community.

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.