JavaScript learning notes (1) basic syntax of JavaScript _ basic knowledge

Source: Internet
Author: User
Tags hasownproperty
JavaScript learning notes (1) Basic JavaScript syntax. If you want to learn JavaScript, refer. 1. Identifiers and keywords
An identifier starts with a letter and can contain letters, numbers, and underscores. The following reserved characters cannot be used for identifiers:

The Code is as follows:


Abstract, boolean, break, byte, case, catch, char, class, const, debugger, default, delete, do, double, else, enum, export, extends, false, final, finally, float, for, function, goto, if, implements, import, in, instanceof, int, interface, long, native, new, null, package, private, protected, public, return, short, static, super, switch, synchronized, this, throw, throws, transient, true, try, typeof, var, volatile, void, while,


In addition, undefined, NaN, and Infinity have specific meanings in javascript, so do not use them either. Javascript does not allow the use of reserved words to name variables or parameters. In addition, javascript does not allow the attribute name of an object to be stored in the literal volume of the object, or after the dot of an attribute access expression, the reserved word field is used.

2. Number
Javascript only has a single numeric type, which is represented as a 64-bit floating point number internally, the same as java's double.

The value NaN is a numeric value that indicates an operation result that cannot produce normal results. NaN is not equal to any value, including itself. You can use the isNaN (number) function to detect NaN.

The Infinity value indicates all values greater than 1.7976931348623157E + 308, that is, the Infinity value.

3. String

The string is unchangeable. Create a New String object for each string change.

The string contains Unicode 16 characters. Javascript has no character type.

A string has a length attribute to obtain the length of a string.

4. Statements

When a variable is defined in a function in a var statement, the defined variable is the private variable of the function. The var statement does not use variables defined by var outside the function or in the function (for example, function () {m = 3.

The code block in javascript does not create a new scope. Therefore, variables should be defined at the top of the function, rather than in the code block.

For... In... The statement can enumerate all attribute names of an object. Generally, you must check object. hasOwnProperty (varible) to determine whether the property name is a member of the object or found from its prototype chain.

For (var pro in Object) {if (Object. hasOwnProperty (pro )){...};}
5. the following values are treated as false: false, null, undefined, empty string "", number 0, and number NaN.
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.