Variable
Data types are divided into primitive types and object types
Primitive types include numbers, strings, and Boolean values
Null and undefined represent unique members of the lattice special type, respectively
Beyond that is the object. An object is a collection of properties, each of which consists of a name-value pair
A generic JavaScript object is an unordered collection of named values. An array is a special object that represents an ordered collection of numbered values.
A function is an object that has executable code associated with it, and is true. If the function is used to initialize (the new operator), a newly created object, called a constructor. Each constructor defines a class (Class) object ————
A collection of objects that are initialized by constructors, and classes can be considered as subtypes of object types.
In addition to array classes, and function classes, there are date classes, regular classes, and error classes. Numbers, Booleans, nulls, and undefined belong to an immutable type.
Digital
The minus sign is a unary negation operator and is not part of the digital direct volume syntax.
Complex arithmetic operations with functions and constants defined by the properties of the Math object
Math.pow (2,8) 2 of 8 power Math.Round (. 6) rounding Math.ceil (. 6) take up the whole math.floor (. 6) want to take the whole math.abs (-5) take absolute value Math.max (x, Y, z) return maximum math.min (x, Y, z) returns the minimum value Math.random () generates a pseudo-random number greater than or equal to 0 less than 1 Math.PI the base math.sqrt of the natural logarithm of pi math.e (3 ) The cubic root of the square root math.pow (3,13) 3 Math.sin (0) trigonometric Functions Math.log (10) The natural logarithm of Math.log (10) math.ln10 100 logarithm math.exp (3) Three power of E
Underflow is what happens when the result of the operation is infinitely close to 0 and is smaller than the minimum value that JavaScript can represent. This will return 0. Negative 0 is returned when the negative number is underflow.
The result of dividing 0 by 0 is a non-numeric value, expressed in Nan. Infinity divided by infinity, to any number of negative root operations or
The arithmetic operator returns Nan when used with an operand that is not a number or cannot be converted to a number
Nan is not equal to any value, including itself when and only when X=nan, X!=x is established
IsNaN () detects if the parameter is a non-numeric value; isfinite () parameter is not Nan, infinity, or-infinity returns True
JavaScript uses binary notation and does not accurately represent numbers like 0.1
var x = 0.3-0.2; 0.09999999999999998 var y = 0.2-0.1; 0.1 = = y; false
The date constructor used to create an object that represents the date and time
var New Date (3, ten); var New Date (); Current date and time var elapsed = now-then ; Date subtraction, the number of milliseconds to calculate the time interval now.getfullyear (); 2015
Now.getmonth (); Number of months now.getdate () calculated starting from 0 ; Number of days Now.getday () calculated starting from 1 ; Week, 0 stands for Sunday now.gethovers (); Current Hour
Text
Escape character
If the \ Post does not conform to the escape character, ignore \
+ For strings means connections
The length property of the string indicates its size
Boolean value
The following values are converted to false
Undefined null NaN 0-0 "" other values are converted to true
null and undefined
Null is a special object value, meaning non-object,
Undefined indicates that the variable is not initialized
Wrapping Object
A temporary object that is created when a property of a string, number, or boolean is accessed becomes the wrapper object reads its property value as if it were the object, but ignores it when assigning a value to a property. JavaScript converts a string to an object by calling the new string () method. This object inherits the method of the string.
var s = ' test '; = 4; // creates a temporary string object, which is then destroyed after the value is assigned var t = S.len; Alert (t); // undefined
strings, Numbers, and Boolean properties are read-only, and you cannot define new properties for them
var s = ' test '; var New String (' Test '); Alert (typeof(s)); // string alert (typeof(S)); // Object alert (s==s); // true alert (s===s); // false
The original value (undefined null numeric string Boolean) is immutable and cannot be changed by any method
Objects are typically referred to as reference types, and comparisons of objects are reference comparisons, and are equal only if they refer to the same base object
Gets a copy of an object or array that needs to be explicitly copied
var a = [1, 2, 3]; var b = []; for (var i = 0; i < a.length; i++) { = a[i];}
Compare two separate objects or arrays and need to compare their properties or elements
function Equalarrays (A, b) { if (a.length! = b.length)returnfalse; for (var i = 0; i < a.length; i++) { ifreturnfalse; } returntrue;
Type conversions
Boolean () Number () String () Object ()
Any value except null and undefined has the toString () method
x + ""//equivalent to string (x)
+x//equivalent to number (x)
!! X//equivalent to Boolean (x)
Number class
toString () accepts cardinality the following methods are rounded tofixed () converts a number to a string based on the number of digits after the decimal point, and does not use exponential notation toexponential () to convert to a string using exponential notation, The number of digits after the decimal point is determined by the parameter toprecision () converts a number to a string based on the specified number of significant digits parseint () resolves only integers, skips any leading spaces, and returns Nan if the first non-whitespace character is an illegal numeric direct quantity. You can receive the second parameter as cardinality parsefloat () to resolve integers and negative numbers parseint (' 44a4 ') //parseint ( ' $11 ') //NaNparseint ('-5 ') //-5
All objects inherit two conversion methods: ToString () and ValueOf ()
ToString () returns a string that reflects the object. The array class converts each array element to a string and adds a comma between the elements to result in a string function class that returns a representation of the implementation definition of the function
ValueOf () Generally returns the object itself, and the date class returns its internal representation: the number of milliseconds since January 1, 1970
var function () { document.write (' hh '); }; Alert (typeof(A.valueof ())); // function var New Date (); Alert (typeof(A.valueof ()));
+ One of the operands is an object, it is converted to the original value
var a = new Date ();
typeof (A+1); String
typeof (A-1); Number
function scope
Variables are defined in the body of the function in which they are declared and in any function within which the body of the function is nested.
function text (o) { var i = 1; if (typeof o = = "Object") {var j =0 ; for (var k = 0; k < ten; k++) { console.log (k); } } Console.log (j); // 0 Console.log (k); // Ten } I j k is defined in the function body
Variable advance: All variables declared in the function (not involving assignment) are "advanced" to the top of the function body
var a = ' AA '; function F (o) { console.log (a); // undefined var a = ' BB '; Console.log (a); // BB }
A local variable in a function body overrides a global variable of the same name, but is only assigned when the program executes to the VAR statement, which is equivalent to a Boolean
function F (o) { var A; Console.log (a); = ' BB '; Console.log (a); }
Declaring a global variable is actually a property that defines a global object. This variable cannot be deleted by delete when declaring a variable with VAR
JavaScript authoritative guide type, value, variable