January 25 JavaScript Introduction and syntax

Source: Internet
Author: User
Tags logical operators

First, JavaScript introduction

(1), Usage:

(1), head inside//head inside main put function

(2), body inside (the body within the most rigorous)

(3),

(2), 3 common dialog boxes

Alert () Warning dialog box, which is the function of a warning dialog to pop up. The dialog box pops up before executing.

Confirm () Determines the dialog box, the function is to pop up a selection of OK dialog box, after clicking OK, it returns True, click Cancel to return flase, available variables to accept.

The prompt () function pops up a dialog box that allows you to enter content. All the strings entered from the box

Note: All of the above three omit window.

Second,JavaScript syntax

(1), Variable type:javascript variable type only one , var. var is a generic mutable type.

(2), Data type: Integer, Decimal, String, Boolean (similar to C #)

(3), type conversion: automatic conversion and casting, generally with cast.

1. How to convert other types to digital type:
parseint ("string")--turns the string into an integral type
Parsefloat ("string")--turns the string into a decimal number


2. How can I tell if a variable is a number?
var a = IsNaN (b); IsNaN--->is not a number

A is true is not a number

A is false is a number

(4), operator

Math operators: +,-*,/,%, + + 、--(7)

Relational operators:>, <, >=, <=, = =,! = (6)

Logical operators: | |, &&,!

Other operators: + =,-=, *=,/=,%=,?:

(5), statement

Order, branching, looping.

1. Branch: If.....else

2. Loop: For

(6), array

1. Definition:

var a=new Array (); Its length is dynamically variable and can be placed in any type of element.

2. Method:

A.sort (); sort an array, Sort by the first character.

A.reverse (); flips an array.

(7), function:

Four elements: function name, input, output, function body

1. Define the function:

function add (formal parameter)

{function body;}

// function name is add , the input is the form of a parameter, and the return value can be a var type or return value.

2, Function call: ( function does not call will not execute)

Add (actual parameter);

Note: JavaScript is case sensitive.

January 25 JavaScript Introduction and 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.