JS usage, output, variable, data type __javascript knowledge summary

Source: Internet
Author: User

First, JS Introduction
JS is an embedded language, can be inserted into the HTML page programming code, is the browser for translation execution.
Divided into three parts: ECMAScript: Is the core of JavaScript, called the interpreter, mainly the code we write to the computer, and then the return of the computer to explain the code to us.
DOM: Document Object model, manipulating HTML
BOM: Browser object model, Operation browser
Second, the introduction of JS
The function is usually placed in the head, or at the bottom of the page, so that it is in the same position without interfering with the page content.
1, inline: The JS code into the <SCRIPT>JS code </script>
2. Outreach: Introduction of JS file <script src= "Myscript.js" ></script>
Third, the output of JS
There are no functions for printing or outputting in JS, but you can output the data in different ways

 1. Window.alert () Pop-up warning box
 2 document.write (), write content to an HTML document, and if this method is executed after the entire document is loaded, the page will be overwritten
 3. innerHTML in JS is bidirectional function: Gets the content of the object  or inserts the content into the  object;
 <div id= "AA" > This is Content </div> 
 We can get the inline content of an object with ID AA by document.getElementById (' AA ') InnerHTML
 , or insert content into an object, such as  document.getElementById (' ABC '). Innerhtml= ' This is the inserted content '; So you can insert content into an object with ID ABC.
 4. Console.log (); Write to the console of the browser. For example, a=1,b=2 can not display the results of a+b on the page, but put them in the console and view the results in the console. Mainly for testing, because he is different from alert, will not interrupt the page operation, easy to debug.

Four, JS variables, JS variables and statements are sensitive to case sensitivity.
1, JS variables, variables are mainly used to store data.
In JS, variables are defined using the var keyword, using = to assign values. The variable must begin with a letter, an underscore, or a dollar sign, but it is not recommended.
You can declare multiple variables in one statement, and use commas to separate Var a=2,b=3,c=4;
Re-declare a variable and the value will not change. The value of Var A=2;var a;a is still 2.
Naming rule: The word is separated from the word by an underscore. Method Name: The first word is lowercase, and the other word is capitalized in the first letter.
Common habits: No types, repeated declarations, implicit declarations, no direct assignment.
2. The JS identifier must begin with a letter, an underscore (_) or a dollar sign ($), and a subsequent character can also use a number.
3, JS in a single note using double slash (//), multi-line comments use (* */*)
4, JS will ignore the extra space, so you can use space to increase the readability of the code.
5, you can use the backslash (\) in the text string to wrap the code.

document.write ("Hello Bye"); no backslash displayed in browser

Vi. Types of data
String, number, Boolean, array, object, null, undefined
Strings can be enclosed in single or double quotes, which do not distinguish between single and double quotes.
There is only one type of number in JS, so you can use the decimal point.
Boolean logic can have only two values, true or FALSE.
Objects are surrounded by curly braces, and the properties of the objects in parentheses appear as names and values (Name:value), separated by commas, and with a colon instead of an equal sign between the attributes and the values.

var person={name= "Zhangsan", age=20};

There are two ways to address an object: P1 = Person.name; P2 = person["name"];
Undefined indicates that the variable does not have a value set and the value of another variable equals null to empty the variable.
When declaring a new variable, you can use new to declare his type. var name = new Stirng; At this point JS variables are objects, and when you declare a variable, you create an object.
JavaScript has an implied global concept, meaning that any variable you don't declare becomes a global object attribute.
Vii. Variable Type
Value type: Occupy the space fixed, save and copy in the stack is the value itself using typeof detection data type basic data type is a value type

Reference type: Occupy space is not fixed, save in the heap and copy is a pointer to an object using the instanceof detection data type the object constructed using the new () method is a reference type

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.