JS Basic syntax

Source: Internet
Author: User

JS: all called: JavaScript. is the scripting language in the Web page.

Code embedding:

<script type="text/javascript"></script>

Try to write it down.

Basic knowledge:

All the characters are in English half-width.

In most cases, a semicolon is added after the end of each statement.

Add a newline after each piece of code ends.

The program echoes (preceded by a parenthesis "(" There must be a parenthesis ending ")").

Comment Syntax:

/* * * Multiple lines of comments.

Single-line comment.

Output syntax:

Alert (Info): Popup message.

Confirm (info): POPs up a dialog box that interacts with the user.

Prompt (info): POPs up a Text dialog box to enter content.

Console.log (Info): output in console.

Data type:

The data is stored in the program, and the stored name is called a variable.

It is divided into strong type language and weakly typed language.

strongly typed languages : The data storage needs to be stored in the corresponding data type variables.

Parameters : Integer (integer) int

Single Precision fractional float

Double-precision Decimal double

Fractional decimal

Currency type Money

Character Char

Strings string

boolean bool (only two states) true false true.

Date Time type DateTime.

Weakly typed languages : When data is stored, the type is not distinguished (type Auto-conversion).

Variable definition:

var a=10

If a variable with a decimal or integer is defined, the value is written directly after the equal sign.

If you define a string variable, the value after the equals sign needs double or single quotation marks

e.g. a= "hello,world!"

type transition:Parse (the type that will be converted).

An operator expression:

mathematical operators : Plus +; minus-; multiply *; remove/; take the remainder%.

logical operators :&& and; | | or;! Non -.

comparison operators : judging whether equal = =;

Not Equal! = or <>.

Greater than >.

Less than <.

is less than or equal to <=.

Greater than or equal to >=.

Other:

concatenation between strings with +. E.g.:alert ("Hello" +aa+ "world" + "!").

Ternary operators:

A==b? " A equals B ":" A is not equal to B "

Determine if they are equal.

Write a Boolean data directly.

JS Basic syntax

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.