JavaScript Basics (1)

Source: Internet
Author: User

1. Preface
    • ECMAScript explanation, used to explain JS code
    • DOM Document Object model, the browser needs to render the DOM tree when it is displayed
    • BOM Browser object model, you can control the browser behavior, code compatibility is poor
2. Basic type

Number type: var a = 12;

String: var a = "string";

function Type: var a = function ()

Object type: var a = document

Boolean type: var a = Boolean

The type of a variable is determined by its assignment.

3. Type conversion
    • Show transformations
<!DOCTYPE HTML><HTML><Head>    <title>Sum</title>    <Scripttype= "Text/javascript">window.onload= function (){               varobtn=document.getElementById ('btn'); Obtn.onclick= function (){            varOINPUT1=document.getElementById ('INPUT1'); varOInput2=document.getElementById ('Input2'); varvalue1=parseint (oinput1.value);//Convert a string to an int            varvalue2=parseint (Oinput2.value); if(!IsNaN (value1)&& !IsNaN (value2))//determine if a variable is a numeric typeAlert (value2+value1); }    }    </Script></Head><Body>    <inputtype= "text"ID= "INPUT1">    <inputtype= "text"ID= "Input2">    <ButtonID= "BTN"type= "button">Sum</Button></Body></HTML>
    • Implicit type conversions

= = value Equal is True

= = = Type is equal and the value equals True

+ String Connector/number addition

-Converts a string to a numeric subtraction operation

4. Scope of variables
    • Closures: Child functions can access variables in the parent function
      function A () {     var temp =1;     Function B () {           temp = 2;     }    }
    • Variable Naming conventions

  

5.json parsing
    • Single Access JSON
<!DOCTYPE HTML><HTML><Head>    <title>Json</title>    <Scripttype= "Text/javascript">    varJSON={A: A, B:"SSS", C:12.4};    alert (JSON.A); Alert (json['b']); </Script></Head><Body></Body></HTML>
    • Iterate through JSON
<!DOCTYPE HTML><HTML><Head>    <title>Json</title>    <Scripttype= "Text/javascript">    varJSON={A: A, B:"SSS", C:12.4}; //TMP is the key, Json[tmp] is the value     for(vartmpinchJSON) alert (json[tmp]); </Script></Head><Body></Body></HTML>

JavaScript Basics (1)

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.