JavaScript definition?
It is a scripting language and requires a host file whose host file is an HTML file.
What does JavaScript have to do with Java ?
No direct contact, java Yes sun Company (already gone, was oracle Span style= "font-family: the song Body;" > acquired), javascript Yes netscape ( Netscape has not, was acquired by the United States online jscript 90% like javascript ie Span style= "font-family: the song Body;" > use on.
Usage
The position in the HTML has three blocks:1.head inside 2.body inside 3. after that, for the sake of insurance generally written in after that. <script language= "JavaScript" > Code must be placed in this area </script>
Three common dialog boxes
Alert ("") warning dialog box, function is to pop up a warning dialog box
Confirm ("") determines the dialog box, the function is to pop up a selection of the OK dialog box, click OK, it returns ture, click Cancel to return flase, the available variables to receive
Prompt (" hint text to display "), which pops up a dialog box that allows you to enter content
1. Basic Data type:
String, Decimal, Integer, DateTime, Boolean, and so on.
2. Variables:
are generic type var, can be stored casually other types of values, can be used directly, not defined, but customary definition. Define variables:var a; all variable definitions are defined with var ,var is a generic mutable type.
3. Type conversion:
It is divided into automatic conversion and casting, which is generally used for casting.
Other types converted to integers:parseint ();
Other types converted to decimals:parsefloat ();
In addition to determine whether it is a valid number type:IsNaN () ;
is isn't a number (not a digit)
Returns true if the number is false, not a number .
4. Operators:
Math Operator:+-*/% + +-;
Relational operators:= = = = > >= < <=;
Logical operator :&& | | ! ;
Other operators : + = = *=/=%=?:
5. Statement:
Generally divided into sequential, branching and looping statements.
(1) The branch is the if statement:
If ( judging condition )
{
Statements that meet the criteria to be executed
}
Else
{
Statement to execute if the condition is not met
}
(2) loop with for statement:
For ( initial condition; cyclic condition; state change )
{
Loop body
}
(3) Problem type: exhaustive, iterative
(4) Two keywords: break and continue
(5) If you want to output the value of a parameter: the value of the output is "+a+" and "+b
6. Array:
The definition of the array: thenew Array (), whose length is dynamically variable, which can be placed in any type of element.
Assignment of array elements:a[0]=123;a[1]= "Hello";
Array value:a[i];
Array properties:a.length; number of array elements, length.
Methods:A.sort (); sort the array, sort by the first character, a.reverse (); flipping an array
7. Function:
Four elements of a function: name, input, return value, processing.
Define functions: FunctionAdd ( 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;
Functions that do not call are not executed, called by the function:Add ( argument ).
JavaScript Basic Syntax