JavaScript syntax

avaScript is a programming language. Grammar rules define the structure of a language.


JavaScript Syntax

JavaScript is a scripting language.

It is a lightweight, yet powerful programming language.


JavaScript Literal

In a programming language, a literal is a constant, as in 3.14.

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

    php中文网(php.cn) 

Run the program and try it


String literal You can use single quotes or double quotes:

    php中文网(php.cn) 

andy

Run the program and try it


Expression literals are used for calculations:

    php中文网(php.cn) 

Run the program and try it


Array (Array) literals define an array:

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

Object literal defines an object:

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

Function (Function) literal defines a function:

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


#JavaScript Variable

In programming languages, variables are used to store data values. A variable is a name. A literal is a value.

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

    php中文网(php.cn) 

Run the program and try it


JavaScript Operator

JavaScript uses arithmetic operators to calculate values:

    php中文网(php.cn) 

Run the program to try it


JavaScript uses assignment operators to variables Assignment:


    php中文网(php.cn) 

Run the program and try it


The JavaScript language has many types of operators:


JavaScript Statement

In HTML, a JavaScript statement is a command issued to the browser.

Statements are separated by semicolons:

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

JavaScript keywords

JavaScript statements usually begin with keywords. The var keyword tells the browser to create a new variable:

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

JavaScript Keywords

Like any other programming language, JavaScript reserves some keywords for its own use.

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

JavaScript keywords must begin with a letter, an underscore (_), or a dollar sign ($).

Following 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 keywords and numbers).

The following are the most important reserved words in JavaScript (in alphabetical order):

Type Instance Description Assignment, arithmetic and bitwise operators = + - * / Description in JS operators Conditional, comparison and logical operators == != < > Comparison in JS Operators are described in
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 with





JavaScript 对大小写敏感。

JavaScript 对大小写是敏感的。

当编写 JavaScript 语句时,请留意是否关闭大小写切换键。

函数 getElementById 与 getElementbyID 是不同的。

同样,变量 myVariable 与 MyVariable 也是不同的。



Continuing Learning
||
php中文网(php.cn)

submit Reset Code
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!