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