[Youpol] basic JS content arrangement (2), Pol js
I. JavaScript Variables
JS variable standards
(1) The variable must contain letters
(2) It can start with $ and _, but is not recommended.
(3) variables are case sensitive.
JavaScript uses var to declare Variables
For example, var carname = "Volvo ";
Value = undefined variables are often declared in computer programs. A variable declared without a value. Its value is actually undefined.
Ii. JavaScript Data Types
String numeric Number Boolean Array Object
Null Undefined
JavaScript Array
Var cars = new Array ("Saab", "Volov", "BMW ");
Var cars = ["Saab", "Volov", "BMW"];
Array subscript is based on 0
JS object
There are two addressing methods for object attributes:
Document. write (person. lastname + "<br> ");
Document. write (person ["lastname"] + "<br> ");
Declare variable type
When you declare a new variable, you can use the keyword "new" to declare its type:
Var carname = new String;
Var x = new Number;
Var y = new Boolean;
Var cars = new Array;
Var person = new Object;
JavaScript variables are all objects. When you declare a variable, a new object is created.
Survival of JavaScript Variables
The lifecycle of JavaScript variables starts from the time they are declared.
Local variables will be deleted after the function is run.
Global variables will be deleted after the page is closed.
JavaScript Functions
Syntax
Function functionname ()
{
// Execute the code
}
Call a function with Parameters
Function functionname (argument1, argument2)
{
// Execute the code
}
Functions with return values
Function myFuntion ()
{
Var x = 5;
Return x;
}
Tomorrow's content
JS scope Js event JS string JS operator JS comparison