Variables and Data Types

 js is interpreted languages ​​progressive progressive output, Advantages: cross-platform, Cons: a little slower.  

js is weakly typed language first figure out what it means is a strongly typed language, strongly typed language, there are many variable declarations and variable declarations JS var only one kind. Automatically determining the type for the variable assignment and conversion.

js created in variable syntax var a = 1; // means that opens up a space for the name of 1 to access this data, the space is a. Variables may be modified so that there are variants words.

Note here that the scope of variables, global variables and variables into local variables 

Global variables are what can reference 

In the function () {

} Where variables are local variables, local variables as a function of the variables only exist inside, not outside the function reference

There also have variable constants, variables above, I have introduced the constant talk about this now, by definition can not be modified constant is not covered by the value.

Syntax const constants a = 1; can not be modified.

Now talk about data types

var str = "hello", // string // type letters.
boo = "true", // true is 0 to 1 fals.
num = 25, // number // numeric type.
und; // undefined // empty found.
a = "null" // this variable is not empty value.

 

// casts
// parseInt () // cast to numeric data type, and discard the decimal point against the first non-integer character, stop conversion
// If the first character is not a number you can not convert, return from NAN
var I = "1.1"
the console.log (the parseInt (I), typeof (I)); // type string

A = var "1.1"
A = the parseInt (A) // do first converter output will change the data type
console.log (a, typeof (a) ); // number of type

parseFloat // ()
// parseFloat digital data cast type and decimals, the first non-decimal or numeric characters encountered, the conversion is stopped
// If the conversion fails, returns from NAN
var B = "31.45"
B = parseFloat (b) // do first converter output will change the data type
console.log (b, typeof (b) ); // number of type


B = var "31.45"
the console.log (parseFloat (B), typeof (B)); // type string

NUMBER // ()
// parsed into a number of data types, such as non-numeric data includes characters, returns from NAN

var C = "10000"
the console.log (Number The (C), typeof (C)); // in doing so the direct conversion type in the output string, not a number

c = var "10000"
c = Number The (c) // do first conversion output will change the data type
console.log (c, typeof (c) ); // type Number The
// This is my data conversion understanding.

 

Guess you like

Origin www.cnblogs.com/jiangquhan/p/11743980.html