JavaScript Basic Grammar Learning Tutorials _javascript Tips

Source: Internet
Author: User

The basic concepts of JavaScript

The JavaScript language is a scripting language that is widely used in Web pages.

Ii. features of JavaScript language:

1. Developed by Netscape, a scripting language based on object and event driven with a certain degree of security.
2. Features:

A JavaScript is a scripting language as well as an interpretive language;
b JavaScript is run by the JavaScript interpreter in the browser, it has nothing to do with the operating environment;
C in JavaScript, the use of a less stringent data types, such as the Russian advantage is in the definition or use of data can be more convenient, but also bring the problem of confusion;
D JavaScript is an object-based language, so that you can create objects on your own and use the properties and methods of the objects you create to produce many functions;
E The main role of JavaScript is to make the Web page move, but also there is a certain interaction;
f JavaScript has security, does not allow users to access the local hard disk, not allowed to modify or delete documents on the network, so as to effectively prevent data loss and malicious modification.
g) Example: HTML file built-in script

<script language= "JavaScript" > document.write ("<font color=blue>hello,javascript!</font>"); </script> HTML file add-in script

JavaScript statements

A command issued to a browser by a JavaScript statement. The function of a statement is to tell the browser what to do.

Semicolon

Semicolons are used to separate JavaScript statements.

Usually we add a semicolon at the end of each executable statement.

Another use of semicolons is to write multiple statements in a single line.

Tip: You may also see a case with no semicolon.

In JavaScript, closing sentences with semicolons is optional.

JavaScript Code

JavaScript code (or only JavaScript) is a sequence of javascript statements.

The browser executes each statement in the order in which it is written.

JavaScript code block

JavaScript statements are combined in the form of blocks of code.

The block starts with the left curly brace and ends with the right curly brace.

The function of a block is to make a sequence of statements execute together.

JavaScript functions are a typical example of combining statements into blocks.

The following example runs a function that can manipulate two HTML elements:

JavaScript is case sensitive

JavaScript is sensitive to capitalization.

When writing JavaScript statements, be aware of closing the case toggle key.

The function getElementById is different from the getElementById.

Similarly, variable myvariable and myvariable are also different.

JavaScript annotations

JavaScript does not perform annotations.

We can add comments to explain JavaScript, or to improve the readability of the code.

A single-line comment begins with//.

JavaScript Multiline Comment

Multiline comment begins with///ends with/*.

JavaScript variables

Like algebra, JavaScript variables can be used to store values (such as x=2) and expressions (such as z=x+y).

Variables can use short names (such as x and y) or better descriptive names (such as age, Sum, totalvolume).

• Variables must begin with a letter

• Variables can also start with the $ and _ symbols (but we do not recommend this)

• Variable names are case sensitive (Y and y are different variables)

Tip: Both JavaScript statements and JavaScript variables are case sensitive.

JavaScript data type

JavaScript variables can also hold other data types, such as text values (name= "Bill Gates").

In JavaScript, a text like "Bill Gates" is called a string.

There are many types of JavaScript variables, but now we focus on numbers and strings only.

When you assign a text value to a variable, enclose the value in double or single quotes.

Do not use quotes when you assign a value to a variable as a number. If you enclose a value in quotation marks, the value is processed as text.

JavaScript Timing Events

By using JavaScript, we have the ability to execute code after a set interval, rather than executing it immediately after the function is invoked. We call it a timing event.

It is easy to use timing events in JAVASCRITP, and two key methods are:

settimeout () code to execute at some time in the future

cleartimeout () cancel settimeout ()

Through the above content to introduce JavaScript basic grammar related knowledge, I hope that the future work of everyone to help.

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.