[JavaScript tutorial] JavaScript syntax

Source: Internet
Author: User
JavaScript is a programming language. Syntax Rules define the language structure.

JavaScript syntax

JavaScript is a programming language. Syntax Rules define the language structure.

JavaScript syntax

JavaScript is a scripting language.

It is a lightweight but powerful programming language.

JavaScript literal

In programming languages, a literal is a constant, such as 3.14.

Number can be an integer, a decimal Number, or a scientific count (e ).

3.141001123e5

Strings can be enclosed in single quotes or double quotes:

"John Doe"'John Doe'

The expression literal is used for calculation:

5 + 65 * 10

An Array (Array) literally defines an Array:

[40, 100, 1, 5, 25, 10]

The Object literally defines an Object:

{firstName:"John", lastName:"Doe", age:50, eyeColor:"blue"}

The Function literally defines a Function:

function myFunction(a, b) { return a * b;}

JavaScript Variables

In programming languages, variables are used to store data values.

JavaScript uses the keyword var to define variables, and uses equal signs to assign values to variables:

var x, lengthx = 5length = 6

Variables can be accessed by the variable name. In a script language, variables are usually variable. A literal is a constant value.


A variable is a name. A literal is a value.

JavaScript Operators

JavaScript uses arithmetic operators to calculate values:

(5 + 6) * 10

JavaScript uses the assign operator to assign values to variables:

x = 5y = 6z = (x + y) * 10

JavaScript has multiple types of operators:/p>

Type

Instance

Description

Value assignment, arithmetic and bitwise operators = +-*/description in JS Operators

Condition, comparison and logical operator =! = <> Description in JS comparison Operators

JavaScript statements

In HTML, the JavaScript statement sends a command to the browser.

The statement is separated by semicolons:

x = 5 + 6;y = x * 10;

JavaScript keywords

JavaScript statements generally start with a keyword. Var keyword tells the browser to create a new variable:

var x = 5 + 6;var y = x * 10;

JavaScript identifier

Like any other programming language, JavaScript retains some identifiers for its own use.

JavaScript also retains some keywords that are not used in the current language version, but will be used in future JavaScript extensions.

The JavaScript identifier must start with a letter, underscore (_), or dollar sign ($.

Subsequent characters can be letters, numbers, underscores, or dollar signs (numbers are not allowed to appear as the first character, so that JavaScript can easily distinguish between identifiers and numbers ).

The following are the most important Reserved Words in JavaScript (in alphabetical order ):

Abstract else instanceof super

Boolean enum int switch

Break export interface synchronized

Byte extends let this

Case false long throw

Catch final native throws

Char finally new transient

Class float null true

Const for package try

Continue function private typeof

Debugger goto protected var

Default if public void

Delete implements return volatile

Do import short while

Double in static

JavaScript comments

Not all JavaScript statements are "commands ". The content after the double slash // will be ignored by the browser:

// I will not execute

JavaScript Data Type

JavaScript has multiple data types: Numbers, strings, arrays, objects, and so on:

Var length = 16; // Number value through the Number literal var points = x * 10; // Number value through the expression literal var lastName = "Johnson "; // String value: var cars = ["Saab", "Volvo", "BMW"]; // Array value: var person = {firstName: "John", lastName: "Doe"}; // assign a value through the Object literal

Concept of Data Types

In programming languages, data types are very important.

To operate variables, it is very important to understand the concept of data types.

If the data type is not used, the following instances cannot be executed:

16 + "Volvo"

16 plus "Volvo", how is computing? Will the above generate an error or output the following results?

"16Volvo"

You can view the effect by executing the above Code in the browser.

In the following sections, you will learn

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.