Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use JavaScript syntax

Shulou Source: shulou.com Published: 2022-06-01 10:53:48 09月30日 Update

This article mainly introduces the relevant knowledge of how to use JavaScript grammar, the content is detailed and easy to understand, the operation is simple and fast, and has a certain reference value. I believe you will gain something after reading this article on how to use JavaScript grammar. Let's take a look at it.

JavaScript is a scripting language, it is a lightweight but powerful programming language.

Each line of code is an instruction and requires a Terminator

JavaScript syntax is strictly case-sensitive!

2.1 literal quantity

In programming languages, a general fixed value is called a literal quantity

The literal quantity of a Number can be an integer or a decimal, or a scientific count (e)

String (String) literals can be in single or double quotation marks

The literal quantity of the expression is used to calculate

Array (Array) literally defines an array

Object (Object) literally defines an object

Function (Function) literally defines a function

/ / numeric literal quantity

3.14

/ / string literals

"John Doe"

/ / literal quantity of expression

1 + 2

/ / Array literals

["eat", "sleep", "code"]

/ / literal amount of object

{"name": "Zhang San", "age": "18"}

/ / function digital face value

Function fun () {...}

2.2 variables

In programming languages, variables are used to store data values, JavaScript uses the keyword var to define variables, and equals signs to assign values to variables

Var a = 1

Var b = 2

Variables can be accessed through variable names. In imperative languages, variables are usually variable. The literal quantity is a constant value.

Note: a variable is a name. The literal quantity is a value

2.3 operator

JavaScript uses the arithmetic operator (+-* /) to calculate the value

Document.getElementById ("demo") [xss_clean] = (7 + 8) * 10

JavaScript uses the assignment operator (=) to assign values to variables

Var a,b

/ / variable assignment

A = 1

B = "JS"

2.4 keyword

The JavaScript keyword identifies the action to be performed. Like any other programming language, JavaScript reserves some keywords for its own use.

These keywords are not used in the current language version, but will be used in future JavaScript extensions:

Let 、 new 、 case 、 class 、 if 、 else.... Keywords such as var cannot be declared as variables!

2.5 comments

Single-line comment

One-line comments begin with / /.

Any text between / / and the end of the line will be ignored by JavaScript (will not be executed)

/ / I am the comment content and will not be displayed.

You can also release the note to the end of the code:

Var x declare 5; / / declare x and assign 5 to it

Var yearly xroom2; / / declare y and assign xroom2 to it

Multiline comment

Multiline comments begin with / * and end with * /.

Any text between / * and * / will be ignored by JavaScript

/ *

This is a multiline comment.

All content will not be parsed and executed.

, /

This is the end of the article on "how to use JavaScript Grammar". Thank you for reading! I believe you all have a certain understanding of the knowledge of "how to use JavaScript grammar". If you want to learn more, you are welcome to follow the industry information channel.

Tags: Literals variables comments languages keywords syntax content programming languages programming code functions objects arrays knowledge operators multilines operations between characters Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple macOS OPPO Reno Microsoft MySQL