First, the data type
1. Strings (String)
var mood = "Happy";
var mood = ' happy ';
2. value (number)
var age = 25;
var price = 33.25;
3. Boolean Type (Boolean)
Boolean data can only have two values of true and false;
var married = true;
var married = false;
Unlike strings, do not enclose Boolean values in quotation marks. A Boolean value of false and the string "false" are two different things.
4. Objects (object)
Date Day Object
Date objects are used to process dates and times.
Code: var today = new Date ();
var year = Today.getfullyear ();
var month = Today.getmonth () + 1;
var day = Today.getday ();
5. array Arrays (object)
The index of an array is set to 0 by default.
Defining arrays
var arr = new Array (23,23,45,56,435);
var arr2 = [23,34,546];
var arr3 = new Array ();
Arr3[0] = 234;
ARR3[1] = 234;
Ii. viewing and conversion of data types
1. View data type typeof
var mood = "Happy";
Alert (typeof mood);
Alert (typeof 95);
2. Convert to String
var married = false;
Alert (married.tostring ()); Outputs "false"
var age = 25;
Alert (age.tostring ()); Outputs "25"
3. Convert to digital
Convert parseint () to integers
Parsefloat () converted to floating point number
Cases:
var test = parseint ("Blue"); Returns NaN
var test = parseint ("1234blue"); Returns 1234
var test = parseint ("22.5"); Returns 22
var test = parsefloat ("1234blue"); Returns 1234
var test = parsefloat ("22.5"); Returns 22.5
4. determine the type of variable
A, Judge the string
typeof (a) = = ' String '
B, judging the value
typeof (a) = = ' Number '
c If it is a numeric type, but the content is not a valid number, it will show Nan, judging nan
IsNaN (a)
D, determine if the variable is empty (no variable is defined.) or define a variable but not initialize it will appear)
typeof (a) = = ' undefined '
Third, operator
1. Arithmetic operators (+-*/%)
Add, subtract, multiply, divide, and balance, where% is the remainder operation
var total = (1 + 4) * 5;
var i = 100;
var temp = (i–20)/2;
Alert ("ten" +)//return 1020;
Alert (+)//return 30;
JavaScript the next day