Introduction to JavaScript and basic syntax

Source: Internet
Author: User

Introduction to JavaScript

1, JavaScript is a scripting language, need to have a host file, his host file is an HTML file.

To use : For the sake of insurance generally written after

Three common dialog boxes:

Alert ("Put Chinese characters in this") Warning dialog box, the function is to pop up a warning dialog, such as alert ("Input error")

Confirm ("") determines the dialog box function is to pop up a selection of OK dialog box, click OK after he returns True, click Cancel to return to Flase.

Prompt ("Hint text to display"), which pops up a dialog box that allows you to enter content. For example:

Prompt ("Several numbers come in, only numbers"), click OK, return only the number, click Cancel to return null value, NULL.

Basic syntax for JavaScript

1, the basic data type:

String, Decimal, Integer, DateTime, Boolean, etc.

2, variables: are generic types of VAR, can be stored casually other types of values, can be used directly, without definition, but the customary definition. Define VAR A: All variables are defined with Var, var is a generic mutable type.

3, type conversion: can be divided into automatic conversion and casting, the general use of casting.

other types are converted to integers: parseint ();

Other types converted to decimals: parsefloat ();

In addition to determine whether it is a valid number type: IsNaN ();

is a number then returns false, not a number if it returns True, as follows:

var a=prompt ("Please enter a number")

if (a!=null)

var B=isnan (a)

if (b==flase)

Then the input of a is a number, continue to go down, if not the number is prompted to enter the error!

4: operator:

A, mathematical operator:+-*/%++--:< Plus is the plus sign when encountering a numeric type, when the type of string is encountered, the three functions are: 1, take the remainder, 2, change a number to a range, 3, and see if it is divisible. + +: Front + + shows +1, after + + equals the original value. >

B, relational operators: = = =! = > >= < <=;

C, logical operator:&& | | !

D, other operators: + = = *=/=%=?; <x=6,y=5 so x+=y x=11, x-=y so x=1.>

5, statements: generally divided into branch statements and circular statements

(1) The branch is the IF statement

if (judging condition)

{

Satisfies the statement to be executed

}

Else

{

Statement to execute if the condition is not met

}

To loop with a for statement:

Introduction to JavaScript and basic syntax

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.