Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the introduction to JavaScript grammar?

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article is to share with you about the introduction of JavaScript grammar, the editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article.

JavaScript is a scripting language. It is a lightweight but powerful programming language. JavaScript literal quantity

In programming languages, a general fixed value is called a literal quantity, such as 3.14.

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

3.141001123e5

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

"John Doe" 'John Doe'

The literal amount of the expression is used to calculate:

5 + 65 * 10

Array (Array) literally defines an array:

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

Object (Object) literally defines an object:

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

Function (Function) literally defines a function:

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

JavaScript variable

In a programming language, variables are used to store data values.

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

Var x, lengthx = 5length = 6

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

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

JavaScript operator

JavaScript uses arithmetic operators to calculate values:

(5 + 6) * 10

JavaScript uses the assignment operator to assign values to variables:

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

The JavaScript language has several types of operators:

Type instance description assignment, arithmetic and bit operators = +-* / describe conditions in the JS operator, comparison and logical operators =! =

< >

Described in the JS comparison operator

JavaScript statement

In HTML, the command issued by the JavaScript statement to the browser.

Statements are separated by semicolons:

X = 5 + 6 * y = x * 10

JavaScript keyword

The JavaScript keyword identifies the action to be performed.

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

The var keyword tells the browser to create a new variable:

Var x = 5 + 6 × var y = x * 10

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

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

Abstractelseinstanceofsuper

Booleanenumintswitch

Breakexportinterfacesynchronized

Byteextendsletthis

Casefalselongthrow

Catchfinalnativethrows

Charfinallynewtransient

Classfloatnulltrue

Constforpackagetry

Continuefunctionprivatetypeof

Debuggergotoprotectedvar

Defaultifpublicvoid

Deleteimplementsreturnvolatile

Doimportshortwhile

Doubleinstaticwith

JavaScript comment

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

/ / I will not execute

JavaScript data type

JavaScript has a variety of data types: numbers, strings, arrays, objects, and so on:

Var length = 16; / / Number is assigned by numeric literal var points = x * 10; / / Number is assigned by expression literal var lastName = "Johnson"; / / String is assigned by literal string var cars = ["Saab", "Volvo", "BMW"] / / Array assigns values through array literals var person = {firstName: "John", lastName: "Doe"}; / / Object assigns values through object literals

The concept of data types

Data type is a very important content in programming language.

In order to manipulate variables, it is important to understand the concept of data types.

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

16 + "Volvo"

16 how is the addition of "Volvo" calculated? Will the above result in an error or output the following result?

"16Volvo"

You can try to execute the above code in the browser to see the effect.

You will learn more about data types in the following chapters.

JavaScript function

JavaScript statements can be written in functions, and functions can be referenced repeatedly:

Reference a function = call the function (execute the statement within the function).

Function myFunction (a, b) {return a * b; / / returns the result of a times b}

JavaScript letter case

JavaScript is case-sensitive.

When writing JavaScript statements, be careful to turn off the case switch key.

The function getElementById is different from getElementbyID.

Similarly, the variables myVariable and MyVariable are different.

JavaScript character set

JavaScript uses the Unicode character set.

Unicode covers all characters, including characters such as punctuation.

The above is how the introduction of JavaScript grammar is, and the editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report