JavaScript (scripting language)

Source: Internet
Author: User

JavaScript (scripting language)
First, the annotation syntax:
1. Single-line comment//comment content
2. Multi-line Comment/* Comment content */
Second, output syntax
JS language format, as far as possible to write, belong to the double label <script type= "Text/javascript" > Middle need to write content </script>
The alert ("...") Displays the Information dialog box, which is the message to eject, for example, alert ("Hello"), and output hello.
Confirm ("..."), interactive dialog box, the user can click OK or cancel, in parentheses is to pop the message. Often used where the user needs to be identified.
Prompt ("..."), enter a dialog box that allows the user to enter a dialog box with the contents to be output in parentheses.

? All characters are in English half-width, and in most cases a semicolon is added after each statement ends.
? wrap, wrap each statement after it ends, making the page code look clear.
Iii. data types: strongly-typed and weakly-typed languages
1, strong type language: storage time data type, such as strongly typed language in the storage of numbers, strings, decimals stored in a different way. Data storage needs to exist in the corresponding data type variables.
2. Weakly typed language: Store without data type, regardless of number, string, fractional storage is stored in the same way. The data is stored in a non-differentiated type (type auto-conversion).
3, the data stored in the program name is called as a variable, in the program where there are two kinds of storage: heap and stack, heap is very large, stack very large.
4. Data type
1) Strong type
①int integral type (integer)
②float Single Precision Decimal
③decimal Double Precision Decimal
④money currency
⑤char characters
⑥string string
⑦bool Boolean type, only two types true (true) and False (false)
⑧datetime Date Time Type

2) Weak type (non-differentiated type)
Variable definition: ① If you define a variable of decimal or integer, the direct write after the equal sign, the equal sign is the function of the direct assignment.
② If you define a string variable, the value after the equals sign needs double or single quotation marks. (in C # the single quotation mark "' stands for character, the double quotation mark" "stands for the string; both single and double quotes can represent characters and strings in JavaScript and PHP)
③ when defining bool type, because there are only two types of bool, you can write directly
var a = 5;
var b= 10.5;
var s= "Hello";
var sex = true;
5. Type conversion (generally not used)
parseint (b); Decimal to Integer
Parsefloat (a); convert integers to decimals
6. Operator expressions
1) Mathematical operators: +-*/%, Division sign in a strongly typed language with only integers, percent percent is the remainder
2) logical operator:&&//and
|| Or
! Non -
3) Concatenation of strings: +
4) Comparison operators:
①==//equals

=//single equals is assignment, = =//Determines whether two values are equal, example


Ternary operators can also be used to determine gender


②!=//Not equal to (written in some languages as "<>")
③>//greater than
④<//Less than
⑤>=//greater than or equal
⑥<=//less than or equal to

Iv. statements
1, the sequential statement, from the last execution, the end to add a semicolon, example var a = 10;
2, branch statement, let the program according to the different conditions to execute different code;
3, the Loop statement,
①if (condition) {code}

The condition does not satisfy the output.


Condition satisfied, output


②if (condition) {code} else{code}

③else if (condition) {code}

④if nested if (condition) {if (condition) {Code}else{Code}}

Example getting user age information


3. Circular statements
Loop operates a function (executes a piece of code), for a specified number of cycles.
Four elements: Cyclic initial value, cyclic condition, state change, loop body.
? For loop: Exhaustive and iterative
To be exhaustive: to enumerate all the circumstances.
Iteration: To use the original value

I=0//Execute initial value
I<10//Condition judgment
i++//Status change
alert (i)//loop body
i++//equivalent to I=i+1
++i//is equivalent to i=i+1, but i++ differs from ++i, for example

? While loop (Dead Loop)

JavaScript (scripting language)

Related Article

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.