Basic syntax for JavaScript

Source: Internet
Author: User

1.JavaScript relationship to DOM:
The browser has the function of rendering HTML code, the HTML source in memory to form a DOM object, is the document object.
Inside the browser there is a JavaScript interpreter/actuator/engine.
Write a JavaScript code in HTML that the JavaScript is executed by the engine, and the result is the operation of the DOM.
And the result of the operation of the DOM is that we often see the special effects, tablets floating, text color.
The host of JavaScript is not just a browser, it can also be a server.

Learning JavaScript mainly distinguishes between:
(1). The syntax of the JavaScript language itself.
(2). Dom Object (body,div,p node tree as an object)

(3). BOM objects (place the browser's address bar, history, DOM, etc.) in an object.

2.

3. Naming conventions:
The variable name of JavaScript can be composed of _, number, letter, $, and the number cannot begin.
Declaring a variable is declared with the VAR variable name.
var a = 34;
var B = 45;
alert (A+B);
Console.log (A,B,A+B);
var $c = ' World ';
alert ($c);
var $= ' jquery ';
Alert ($);

Note: Variables in JavaScript need to be case sensitive. STR and STR are not a variable.
Note: Without Var, the global variables will be polluted.

Variable type of 4.//JS
var a = 23;//integer type
var B = 3.14;//Floating-point number type
var c = "Hello";//String type
var d = ' world ';
var e = true; BOOL Type
var f = null;//No object data
var g = undefined;//No original data
var h = {name: ' Lisi ', age:20};//associative array, object type
Console.log (H.name);
Console.log (h[' name ');

var arr=[' A ', 3, ' Hello ', true];//array always starts incrementing from 0,1,2 ...
Console.log (arr);
Alert (arr);
Console.log (arr[2]);


concatenation operator "+" in 5.//js
Console.log (2+3);
Console.log (' hello ' + ' + ' world ');
Console.log (2+3+4+ ' haha ' +5+6);//9haha56, once the illegal numbers are encountered, the following are directly spliced.

The logical operation in JS, which returns the first value that can judge the result of an expression.
var a = false;
var B = 6;
var C = true;
var d = (a| | b| | c);
var e = (a| | c);
Console.log (d);//6
Console.log (e);//true
Console.log (a&&b);//flase

Control structure in 6.JavaScript:

var arr = [' Zhao ', ' money ', ' sun ', ' Li '];
for (var i = 0; i < arr.length; i++) {
Console.log (Arr[i]);
}
var obj = {
Name: ' Lisi ',
Age:29,
Area: ' BJ '
};
For (var k in obj) {
Console.log (k + ' ~ ' +obj[k]+ ' ~ ' +obj[' K ']);
}
/* Run Results
name~lisi~undefined
age~29~undefined
area~bj~undefined
*/


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Basic syntax for JavaScript

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.