JavaScript syntax



 JavaScript is a programming language. A program basically writes a series of instructions to tell the browser what to do.

We call JavaScript program instructions a statement. A program will consist of many statements, and the browser will execute these statements in order from top to bottom and from left to right.

Statements define the main syntax in JavaScript. Statements usually use one or more keywords to describe what you want to do. The statement can be very simple, such as executing a function; or more complex, such as a logical judgment block (if else).

semicolon ;

JavaScript each statement with a semicolon ;do end.

JavaScript's semicolon ;may be omitted (optional), but in order to make the code more clearly avoiding possible for code parsing error after take off, generally best used to add a semicolon.

Variable

The purpose of variables is to store and read data from variables:

  • You can use the varkeyword to declare a variable
  • With =equal sign to a set value (value) to the variable

For example, we declare a variable x and set the value of x to 100:

var x;
x = 100;

You can also specify the value while declaring the variable:

var x = 100;

Operator (Operator)

JavaScript has many different types of operators to allow you to do different operations.

Like the assignment operator (assignment operator) =equal sign, used to assign a value to a variable:

var x = 100;

Or like an arithmetic operator (arithmetic operator) + - * /, used to operate on values:

var x = 100 + 20;
var y = x + 50;

The value of the x variable above will be 120, and the value of the y variable will be 170.

Comment

As the name implies, annotations are written for developers to read. The annotation syntax tells the browser to ignore and not execute this statement.

JavaScript comments are divided into single-line comments (double slash //) and multi-line comments ( /* Use the "/*" and "*/" symbols, all words enclosed in the middle are comments */).

// This is a single line comment

/*
this is...
many
Row
annotation
*/

Whitespace

Blank (space), tab or newline characters (newline characters) are called whitespace in JavaScript. When JavaScript code is parsed, all whitespace will be ignored, so you can freely use whitespace characters to compose your code. Make it easier to read.

var x = ['stringggggggggg1', 'stringggggggggg2', 'stringggggggggg3'];

// This wording is exactly the same as above
var x = [
    'stringggggggggg1',
    'stringggggggggg2',
    'stringggggggggg3'
];

Case sensitive

Unlike HTML, JavaScript statements are case-sensitive, whether it is for variable, function or object names, such as alert() written as Alert() will cause an error.

Post a Comment

0 Comments