Variable
Person=null; Empty variables
Carname= "Volvo"; Assign to an undeclared variable, it will become a global variable, even inside the function
Window.carnam; All data variables belong to the Window object
Character accessing a string: Using the location index
var carname = ' Volvo XC60 ';
var character = carname[7];
var y = new String ("John"); Do not use this method to declare variables
Data type
typeof [1,2,3,4]; Return object
typeof null; Return object
typeof new Date (); Return object
typeof new Array (); Return object
typeof NaN; return number
var answer; Console.log (typeof answer); Back to undefined
typeof undefined; Undefined
typeof null; Object
NULL = = undefined//False
NULL = = undefined//True
typeof function () {}//return function
typeof ABC; Back to "undefined"
5 Types of data:
String
Number
Boolean
Object
function
3 Types of objects:
Ojbect
Date
Array
3 types of data that do not contain any values:
Null
Undefined
Number (""); Returns 0
Number (""); Returns 0
Number ("99 88"); Return NaN
JS exception
try{
var X=document.getelementbyid ("Demo"). Value;
if (x== "") throw "empty";
}catch (Err) {
var Y=document.getelementbyid ("mess");
Y.innerhtml= "Error:" + err;
}
Javascript:void (0) means dead link , click No response
JS function
declaration by expression :
var x = function (A, b) {return a*b;}
functions can be called before a declaration : only function mode
MyFunction (5);
function MyFunction (y) {
return y*y;
}
self-calling functions :
(function () {
var x = "Hello";
})();
Functions can be used as a value:
function func (x, y) {
return x*y;
}
var a = func (4,3);
var B = func (4,3) + 5;
Default Parameters :
function myFunction (x, y) {
y = y | | 0;
}
Arguments object:
var x = SumAll (1, 123, 500, 115, 44, 88);
function SumAll () {
var i, sum = 0;
for (i = 0; i < arguments.length; i++) {
Sum + = Arguments[i];
}
return sum;
}
Call/apply: Calling function
function MyFunction (A, b) {
return a * b;
}
Myfunction.call (MyObject, 10, 2);
MyArray = [10,2]; Myfunction.apply (MyObject, MyArray);
;
JavaScript Basics (third time)