JavaScript series knowledge - JavaScript data types and type conversion

JavaScript series knowledge - JavaScript data types and type conversion

1. JavaScript data types

String, Number, Boolean, Array, Object, Null, Undefined.

JavaScript has dynamic typing, which means the same variable can be used as different types, say, var x; x is undefined, var x = 5; now x is a number

1. JavaScript strings

Strings are variables that store characters. Strings can be arbitrary text in quotes. You can use single or double quotes. For example, var carname=”Volvo XC60”; can use quotation marks in the string, as long as it does not match the quotation marks surrounding the string.

2. JavaScript numbers

JavaScript has only one numeric type. Numbers may or may not have a decimal point. Very large or very small numbers can be written using scientific (exponential) notation.

3. JavaScript Boolean

Boolean (logical) can only have two values: true or false. Booleans are often used in conditional tests.

4. JavaScript arrays

Array subscripts are zero-based, so the first item is [0], the second is [1], and so on.

5. JavaScript Objects

* objects are delimited by curly braces. Inside parentheses, an object's properties are defined as name and value pairs (name : value). Attributes are separated by commas, eg, var person={firstname:"John", lastname:"Doe"};
*Spaces and line breaks don't matter. Declarations can span multiple lines:

var person={
    firstname : "John",
    lastname  : "Doe"
};

*Object properties have two addressing modes: dot syntax and bracket syntax

6. JavaScript's Undefined and Null

*Undefined This value indicates that the variable does not contain a value.
*Variables can be cleared by setting their value to null.

Second, declare the variable type

When declaring a new variable, you can use the keyword "new" to declare its type: var carname=new String;
JavaScript variables are objects. When you declare a variable, you create a new object.

To be continued

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325494224&siteId=291194637