Basic syntax for JavaScript

Source: Internet
Author: User

Variable

1). Understanding: A variable is an identification of the memory used to store variable data

2). Definition: Defined by var


var i = 1;alert (i); i = "abc"; alert (i);

Data type 1). Type classification of data:

L Basic Type: numeric (number), String, Boolean (Boolean), undefined

L Object types: Objects (object), arrays (array), functions (function)

2). The type of the variable:

L Basic Type: variable that holds basic type data

L Reference type: A variable that holds the address value of the object type data


The reference type, just the address where the data is saved.


3). Detailed: Basic type data

A. Numeric type (number)

Integers and decimals

Infinity

NaN

B. String types (String)

Definition: The data "HelloWorld" ' HelloWorld ' of a pair of single quotes or double-quoted packets

C. Boolean value type (Boolean)

Only true and false two kinds of values

D.undefined type (differs from "undefined")

Its value is ' undefined ', if the variable is not assigned, i.e. its value is undefined


var u; Undefined (not initialized or undefined) alert (typeof i);



4). Introduction: Object type data

A. Object: A collection of properties, that is, a hash list of key values

B. Array: Ordered list

C. Function: Object data that contains executable code


5).conversions between data types:

A. String of basic type String---> Object type

str = "123"; str = Str/1;//alert (typeof str);//number automatically converted to base type values


B. Numeric string--->number


str = "123"; str = str + 1; is a connector//alert (str); "1231"


C. Any type of--->boolean type

1. Data that can be automatically converted to false: empty string, null, undefined, 0,nan

2. All others are true

</pre><p align= "left" ><pre name= "code" class= "javascript" >STR = "123"; str = Str/1;//alert (typeof str );//number automatically converts to the basic type value str = "123"; str = str + 1; is a connector//alert (str); "1231" str = str * 1;//1231STR = str + 1;//1232 is an arithmetic operator//alert (str); str = null;if (!str) {//alert ("----1");} str = "a"; if (str) {//alert ("----2");} str = 0;if (!str) {//alert ("----3");} str = undefined;if (!str) {//alert ("----4");}



Operator (Special)

1). Parentheses: () to define or invoke a function

2). Bracket operator: [] used to create an array/get array elements

3). Curly brace operator: {} used to create an object

4). Colon operator: Colon is used to separate the property name and property value of an object

5). typeof: The string that corresponds to the data type used to get the variable

6). instanceof: Determines whether an object is of the specified type

7). Delete: Delete the specified data



Use of functions

1). function

function sum (n, m) {

return n + m;

}
2). var + function

var sum2 = function(n, m) {

return n + m;

};


Parameter problems with functions

L arguments can not be inconsistent with formal parameters

L can dynamically obtain real parameters in a function.

L Arguments: There is a built-in reference variable in each function that points to an array of all the arguments that represent the call to simultaneous


var sum4 = function() {

var result = 0;

for (var i = 0; I <arguments.length; i++) {

result+= Arguments[i];

}

return result;

}



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Basic syntax for JavaScript

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.