Home  >  Article  >  Web Front-end  >  JavaScript study notes (1) js basic syntax_basic knowledge

JavaScript study notes (1) js basic syntax_basic knowledge

WBOY
WBOYOriginal
2016-05-16 18:00:17879browse

1. Identifiers and keywords
Identifiers start with letters and can contain letters, numbers, and underscores. Identifiers cannot use the following reserved characters:

Copy code 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, with

In addition, undefined, NaN, Infinity have specific meanings in JavaScript, so do not use them either. JavaScript does not allow reserved words to be used to name variables or parameters. Moreover, JavaScript does not allow the use of reserved words to position the property names of objects in object literals or after the dot in a property access expression.

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

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

The value Infinity represents all values ​​greater than 1.7976931348623157E 308, that is, infinite values.

3. String

String is immutable. A new string object is created every time the string changes.

The string contains Unicode 16-bit characters. There are no character types in javascript.

String has a length attribute, which can get the length of the string.

4. Statement

When the var statement defines a variable inside a function, the defined variable is a private variable of the function. The var statement outside the function or the variables defined without var within the function (used directly, such as: function(){m=3;}) are global variables.

Code blocks in JavaScript do not create a new scope, so variables should be defined at the top of the function, not within the code block.

for … in … statement can enumerate all attribute names of an object. Usually you have to check object.hasOwnProperty(varible) to determine whether the property name is a member of the object or found in its prototype chain.

for(var pro in Object){ if (Object.hasOwnProperty(pro)) { ... };}
5. The following values ​​are treated as false (false): false, null, undefined, Empty string " ", number 0, number NaN.
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn