JavaScript foundation
1, annotation method
(1). A single line comment
// This is a single line comment
(2) Multi-line comments
/ *
This is a multiline comment
* /
2, the basic data types
Data types can be detected by typeof: Number (number), String (String), Boolean (Boolean), Object (Object), Function (function), undefined (undefined).
Object common data types: Array (array value of the data type objects to Object), null (empty, the value of the data type objects to Object).
3. Where write js code
a. tag can be written in the script (script tag can theoretically be placed anywhere in the HTML file, the actual development is generally placed in the body or head) (inline)
. B writes tag event attributes (columns such as: onclick) (inline)
c. wrote external js file. (external)
4, JavaScript is not indented problem, represents a block of code in curly brackets.
5, the operator
(1) mathematical operators: +, -, *, /,%, +, -
a -., +, *,%, and in the mathematical sum, difference and product demand, taking the same I
b. / and mathematics in addition to the same
c ++, -. (unary operator)
Syntax: ++ variable, the variable - / ++ variable - Variable
Difference: after the first assignment, then operation; in front of the first operation, then the assignment
++: Since a plus
-: Since a Save
(2) comparison operators:>, <, = = (equal), =,> =, <=, === (exactly equal), ==> == <==!!
The result is a Boolean value
(3) logical operators (&&: and (a false is false), ||: or (a true is true),! Non ())
(4) assignment operator: =, + =, - =, * =, / =,% =
The left side of the assignment operator must be variable.
(5). Ternary operator (? :)
The basic format:
conditional statements? Value 1: Value 2
results:
Are the results to determine the condition statement is true, if it is true, then the result of the expression is the value of 1, otherwise a value of 2
(6) The priority of the operator
Assignment operator <Logical Operators <comparison operators <arithmetic operator
() can be modified by the addition.
Data type conversion 6.JavaScript
Number () is converted into a digital, String () is converted to a string, Boolean () is converted to a Boolean value.
Global method Number () can be converted to other types of numbers. This method can be used for any type of numbers, letters, variables, expressions
Global method String () can be converted to a string of other types. This method can be used for any type of numbers, letters, variables, expressions
Boolean global method () can be converted to another type Boolean. This method can be used for any type of numbers, letters, variables, expressions
1. converted into other data types Type number
(1) parseInt () to convert into other data types tend to convert a string type Integer
Features:
i): from left to right parsing encountered non-numeric characters, then stop parsing, output has been parsed digital
ii): If the first character is non-numeric characters, can not be converted to give NaN
(2) parseFloat () to convert into other data types Decimal
Like parseInt characteristics, the only difference is that we can resolve the decimal
2. The digital front +
Features:
With the principle Number () conversion of the same features, too
+ As the inside of the mathematical sign to use
7.Math
Math Common Object Properties
Math.E attribute represents the arithmetic constants to e, the base number of the natural logarithm of the value of approximately 2.71828.
Math.PI. PI attribute is π, and the circumference of a circle to its diameter ratio. This value is approximately 3.141592653589793.
Math Common Object Methods
Math.abs (x). ABS () method returns the absolute value of.
Math.pow (x, y). POW () method returns the value of x of the power of y.
Math.max (x ...). The larger the number value max () method returns the two designated with numbers. (Zero or more values)
Math.min (x, y). min () method returns the number specified in number with the lowest value. (Zero or more values)
Math.floor (x). floor () method can be rounded to the next number a
Math.ceil (x). ceil () method a number of rounded on.
Math.random (). random () method returns a random number ranging between 0 and 1.
Math.round (x). round () method a number rounded to the nearest integer. (rounding)
8.Number
Number Common Object Properties
Returns the largest number in Javascript: Number.MAX_VALUE;
Returns Javascript minimum number: Number.MIN_VALUE;
Return to positive infinity: Number.POSITIVE_INFINITY;
Return negative infinity: Number.NEGATIVE_INFINITY;
Number object methods
IsFinite detect whether the specified parameter is infinite.
toExponential (x) to convert the value of the object to exponential notation.
toFixed (x) is converted to the digital string has a specified number of decimal places of the result.
toPrecision (x) to a digital format for the specified length.
toString () to convert the digital strings, the specified base.
valueOf () returns a numeric value substantially Number object.