JavaScript data Types
A string (string), a number, a Boolean (Boolean), an array, an object (objects), null (NULL), undefined (Undefined ).
Eg:var variable_name= "JavaScript Everyday Learning 2"//String
var variable_name=3.14//decimal var variable_name=3//Integer
var variable_name=true//Boolean (FALSE)
var variable_name=new Array ("1", "2", "3"); Array--"var variable_name=[" 1 "," 2 "," 3 "];
var variable_name=new Array (); Variable_name[0]= "Saab"; Variable_name[1]= "Volvo"; Variable_name[2]= "BMW"; //Self - defined array
var variable_name=new String (); Object
var variable_name=new number (); Object
var variable_name=new Boolean (); Object
var variable_name=new Array (); Object
var variable_name=new Object (); Object
var variable_name=null && var variable_name; Null (NULL), undefined (Undefined)
There are four ways of array:
var arr1 = new Array (' A ', ' B ', ' C '); This is a predefined array that, when created, initializes var arr2 = [' A ', ' B ', ' C ']; This is also initialized at the time of creation, but this creation is more concise and intuitive var arr3 = new Array (); var arr4 = []; Both of these are created with an empty array
In the array operation, the most notable is the use of subscript, error-prone
The creation of objects, generally recommended to use
var people = {name: ' Tom ', age:21, Eat:function () {} }
You can also create objects and append properties and methods first
var people = new Object ();p eople.name = ' Tom '; People.age = +; People.eat = function () { }
creation and access of JavaScript objects
The first type:
function Demo () {var obj=new Object (); MultiRow create an object instance Obj.name= "Zhang Sizhong's"; obj.age=12; Obj.firstf=function () {} obj.secondf=function () {}
var obj={name: "Zhang Sizhong's", Age:12,firstf:function () {},secondf:function () {}}; Single-line Create object instance return obj;} var one=demo ();//Call Output document.write (one.age);
document.write (ONE.FIRSTF ());
The second type:
function Demo () {this.name= "Zhang Sizhong's"; this.age=12; This.firstf=function () {} this.secondf=function () {}}var one=new demo//call output document.write (one.age);
document.write (ONE.FIRSTF ());
JavaScript variables and their scopesLocal variable: A variable declared through Var in a function.
Global variable: A variable declared through Var outside of a function.
A variable that is used without a declaration, the default is a global variable, regardless of where the variable is used.
The JavaScript variable life cycle is initialized when it declares.
Local variables are destroyed after the function has finished executing.
Global variables are destroyed after the page is closed.
JavaScript Daily Learning 2