Basic syntax for JavaScript

Source: Internet
Author: User
Tags tag name

Basic syntax for JavaScript

What are the basic syntax requirements for JavaScript? Let me introduce you to the following:

1.javascript Order of execution

Follow the order in the HTML file in sequence.

2. Case-sensitive

JavaScript distinguishes between character case, two strings of the same case, and will be considered different strings. In addition, JavaScript keyword is also case-sensitive, to strictly follow the syntax required to write.

3. Writing format

JavaScript ignores whitespace and line breaks, to use ; to end a statement. It can write multiple statements in one line, the last line of the semicolon class can be omitted but try not to omit. In order to improve the readability of the program, we should use these formats, which is a clearer and more readable change to the program.

4. Comment statements

In order to improve the maintainability and readability of the program, there should be some comment statements. He reads it to the programmer and, of course, it is to prevent you from looking back at these statements to remember what he used to do. A single-line comment is usually started by//. Multi-line comments are commented by/* */.

1 //I am a single-line comment 2 /* 3    I am a multiline note 4    I am a multiline comment   5 */
Reserved words in 5.javascript

JavaScript retains a subset of the words used for specialized purposes, which we call reserved words. Reserved words cannot be used for naming constants, functions, and so on. There are some special words that we cannot use to name in order to avoid ambiguity. Here is the reserved word for JavaScript.

Error in 6.javascript

(1) syntax error: Debug via console.

(2) Logic error: Debug error via alert () popup box.

7.javascript 4 ways to get HTML tags

Get ID

1 document.getElementById (' id ')

Get class

1 document.getelementsbyclassname (' class ')

Get tag Name

1 document.getelementstagname (' tag name ')

Get Name

1 document.getelementsname (' name ')

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.