English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Basic Syntax, Types, Variables
Methods for determining non-numeric values: (because Infinity and NaN do not equal any value, including themselves)
1, use x != x, when x is NaN, return true;
2, use isNaN(x), when x is NaN or a non-numeric value, return true;
3, use isFinity(x), when x is not NaN, Infinity,-When x is Infinity, return true;
Although (strings, numbers, booleans) are not objects, their properties are read-only, but they can also be referred to and operated like objects, the principle is:
JavaScript constructs a temporary object (String, Number, Boolean) (called a wrapper object), and then calls its properties and methods through this temporary object. The properties and methods that change are only this temporary object, and the temporary object will be destroyed later. The changes made do not affect the original data;
You can explicitly construct a wrapper object whose value is equal to the original data '==', but the types are different '==='
Convert number a to string:
a.toString(n) //n represents the base
a.toFixed(i) a.toExponential(i) a.toPrecision(j) //i is the number of decimal places, j is the number of digits to display
Convert string s to decimal number: (ignore leading spaces, convert as many numbers as possible, ignore the non-numeric content behind, where '0X' and '0x' start, it will be treated as16convert from a base number)
parseInt(s,[n]) //n represents the base, an optional parameter, converts s to a decimal number as an n base number
parseFloat(s,[n])
Object automatically converts to string steps:
1.If there is a toString() method and it can return the original value, then call it, which will convert the original value to a string;
2.If the first step is invalid, then call valueOf(), which will convert the original value to a string;
3.If the first two are both invalid, then a type error exception will be thrown;
Object automatically converts to number steps:
1.If there is a valueOf(), then call it, convert the original value to a number, and it can return this number;
2.If1is invalid, then try to call toString(), convert the returned original value to a number and return that number;
3.If1,2are all invalid, then a type error exception will be thrown;
The Date object is an exception
Variable declaration ahead:
When calling an undeclared variable, the declaration part will be brought forward during compilation, while the initialization part will remain in place;
(Re-declared variables, the local ones will override the external ones)
var s1 = 'ggggg'; function f() { console.log(s1); //s1 == undefined var s1 = 'cccccc'; console.log(s1); //s1 == 'cccccc' }
Bitwise operations: & | ^ ~
&: Bitwise AND, the AND operation is performed on the two integer operands on the left and right, and only when the corresponding bits are1when one of the corresponding bits is1;
|: Bitwise OR, the result is1then the result is1;
^: Bitwise XOR, corresponding bits are 0 if the same, and1;
~: Bitwise complement, unary operator, all bits are inverted, equivalent to changing the sign and subtracting1;
(n is 0~31between)
<<n: All bits are shifted to the left by n bits, which is equivalent to multiplying the value by2to the nth power, discard the most left n bits, and fill the right n bits with 0;
>>n: All bits are shifted to the right by n bits, ignore the right overflow bits, the left bits are filled with the original operand, and the result is equivalent to dividing2to the nth power, discard the remainder,7>>1=3 , -7>>1=-4
<<<n: The same as <<, but 0 is used to fill the left bits
String comparison size:
JavaScript strings are composed of16The comparison of character series composed of bit integer values is the numerical value of their characters, and the numerical value of uppercase and lowercase characters is different;
Comparison operators prefer numbers, and numeric operations are performed as soon as one of the operands is a number, only when both are strings, string comparison is performed
While '+The 'operator prefers strings, and string concatenation is performed as soon as one of the operands is a string
x in p
Check if there is a property x in the object p, including methods
a instanceof A
Check if the object a is an instance of class A, including the detection of its parent class
False values: false, null, undefined, 0,-0, NaN, ""
True value: all values except the above are true values;
Object: all values except strings, numbers, true, false, null, undefined are objects!
That's all for the JavaScript learning notes written by the editor_ Briefly discuss the basic syntax, types, and variables. I hope it will be helpful to everyone, and please support the Shouting Tutorial~