JavaScript Daily Learning 2

Source: Internet
Author: User

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)

  1. 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 () {  }
  2. 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 scopes

    Local 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.