Variable
Variables in JavaScript are represented by a variable name, which is a combination of uppercase and lowercase English, numeric, $ and, and _ can only be preceded by letters, underscores, and $ . The variable name cannot be a JavaScript keyword, such as if , and while so on. Declare a variable var关键字 , for example:
var // declaring variable a var b = Ten; // declaring variables and assigning values var $a = "string"; // declaring a variable starting with a $ character var true; // Declare variables with _ var NULL ; var $b = undefined;
Note: variables are strictly case-sensitive.
Writing Specifications for variables:
1, Camel style--the first word lowercase, the rest of the first letter of the word capital. such as: Mynameislee
2. Underline style--the word is unified lowercase and the word is separated from the word by an underscore. such as: My_name_is_lee
Note: In the development process, you should keep the entire project consistent regardless of which writing specification is used.
Data type
in JavaScript, there are 6 types of data, namely numeric (number), Boolean (Boolean), String-type (string) , undefined, null, object type. The first four are basic data types, and Null is a special type, and object is a composite data type.
Number
JavaScript does not distinguish between integers and floating-point numbers, and is uniformly represented by number, and the following are valid number types:
// integer 1234 // floating point 1.456 // scientific notation means 1.235x1000, equivalent to 123.5 // Negative number // Nan means not a number, which is represented by Nan when the result cannot be evaluated // Infinity is infinitely large, and is represented as infinity when the value exceeds the maximum value that JavaScript can represent.
JavaScript variables and data types