Basic JavaScript Concepts

Source: Internet
Author: User

The syntax in JS is heavily borrowed from C and other Class C languages (Java,perl).

Everything in JS (variables, function names, operators, etc.) are case-sensitive. such as "Var A;" Variable A with "Var A;" In the Variable a differs in the. Typeof,valueof,instanceof and so on are case-sensitive.

The naming rules for identifiers (variables, function names, parameter names, and so on) in JS: Hump naming style. The first character cannot be a number, it can be a letter, an underscore, a $ symbol, and other characters can be numbers, letters, underscores, and $.

JS code Comment://single-line comment,/** code block **/multiline Comment

The identifier in JS cannot be the same as the keyword. For example, if you define a variable or function, the name cannot be typeof, because TypeOf is the key word in ES;

Variable: The variable in JS is loosely typed (meaning that the variable in JS can hold any type of value). Each variable is just a placeholder for a saved value.

Variable declaration method: var variable name;

Note: variables defined with the VAR operator will become local variables that define the scope of the variable.
For example, you define a variable at the beginning of a JS file (and outside the function): var first = 1; then this variable first is the local variable of the entire JS document, and the variable is automatically destroyed when the entire document is executed;

Again such as:

function f () {var first = 1;}

Then this variable first is a local variable in the scope of the function f (), and when the function f () is executed, the variable is automatically destroyed.

You can also omit the operator Var to create a global variable. (This is not recommended, because defining global variables in local scopes is not easy to maintain)

function f () {first = 1;}

In this notation, the variable first is a global variable. Outside of the function, you can still access the variable.

Note: "What is a scope?" will be explained later. "and" JS garbage collection mechanism. "


Basic JavaScript Concepts

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.