JavaScript Advanced Programming 3 Chapter III: Basic Concepts Chapter Content syntax data type flow control statement function

Source: Internet
Author: User
Tags hasownproperty

3.1 Syntax

ECMAScript's syntax draws heavily on the syntax of C and other classes of C languages.

3.1.1 Case Sensitive

3.1.2 Identifier

A so-called identifier is a value variable, a function, the name of a property, or a function parameter. Identifiers can be one or more characters that are combined according to the following formatting rules:

(1), the first character must be a letter, an underscore, or a dollar sign;

(2), other characters can be letters, underscores, dollar signs or numbers;

PS: The letter of the identifier can also contain extended ASCII or Unicode alphabetic characters, but we do not recommend it; it is best to use the hump naming method; You cannot use keywords, reserved words, true, false, and NULL as identifiers.

  3.1.4 Strict mode

"Use strict";

In strict mode, the results of JavaScript execution can vary greatly.

3.3 Variables

The ECMAScript variables are loosely typed, and so-called loose types can be used to hold any type of data. In other words, each variable is just a placeholder for saving the worth of placeholders. Use the var operator when defining a variable (note that var is a keyword) followed by the variable name (that is, an identifier). (Uninitialized variables will hold a special value undefinded); the variables defined in the function are destroyed when the function is launched. (without var to define the variable, will be directly into the family variables, not recommended to use, to avoid pollution overall)

3.4 Data types

5 basic types (undefined,null,boolean,string,num), 1 kinds of complex data types (object);

object is essentially a set of unordered name-value pairs.

3.4.1 typeof operator

Using the typeof operator on a value may return the following string:

(1) "Undefined"--if this value is undefined;

(2) "Boolean"--if this value is a Boolean value;

(3) "string"--if the value is a string;

(4) "Number"--if the value is an array;

(5) "function"--if the value is a function;

(6) "Object"--if this value is an object or null (ps:typeof null returns "Object" because a special value of NULL is considered a reference to an empty object)

Ps:alert an undeclared variable will report an error, but the typeof detects an undeclared variable without an error and will only be reported undefined)

The ps:undefined value is derived from a null value and is equal to 2 when judged by = =

3.4.5 NAN

IsNaN () False if there is a number, otherwise true; (0 divided by 0-bit Nan);

3.4.6 String Type

The escape sequence is parsed as a character;

Features of the string:

(1) The strings in the ECMAScript are immutable, that is, once the strings are created, their values cannot be changed. To change the saved string of a variable, first destroy the original string, and then populate it with another string that contains the new worth of strings: 1 creates a new string that holds the total number of characters, 2 fills the character to be filled, and 3 destroys the original character. (This process occurs in the background)

Convert to String:

The 1:tostring () method (except null and undefined does not have this method, the others are more);

3.4.7 Object Type

The object in Ecmascipt is actually a set of data and functions. An object can be created by executing the new operator followed by the name of the object type to be created.

Each instance of object has the following properties and methods.

1:construct: Holds the function that is used to create the current object.

2:hasownproperty (PropertyName): Used to check whether a given property exists in the current object instance (not in the instance's prototype);

3:isprototyoeof (object): Used to check if an incoming object is a prototype of the current object

4:propertyisenumerable (PropertyName): Used to check whether a given property can be enumerated using the For-in statement. As with the hasOwnProperty () method, the property name as a parameter must be specified as a string.

5:tolocalestring (); Returns the string representation of an object that corresponds to the region of the region where the environment is executed

6:tostring (); Returns the string representation of an object

7:valueof (): Returns the string, numeric, or Boolean representation of an object. Usually the same as the return value of the ToString () method.

PS: Objectin ECMAScript is the basis of all objects, so all objects have these basic properties and methods.

3.5.8 conditional operator (ternary expression also called trinocular expression)

JavaScript Advanced Programming 3 Chapter III: Basic Concepts Chapter Content syntax data type flow control statement function

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.