. Record what you didn't know before.
| variables |
explain |
Example |
| string |
String, a section of text. To indicate that variables are strings, you should wrap them in quotation marks. |
var myvariable = ' Bob '; |
| number |
number, one number. Surround it without quotes. is a single data type, internally represented as a 64-bit floating-point number , as with a double in Java. Nan is a special value. It is not equal to its own. |
var myvariable = ten; |
| boolean |
Boolean, a True/false (True/False) value. &NBSP true / false is a special keyword in JS that does not require quotation marks. |
var myvariable = true; | The
| array |
Array, a structure that allows you to store multiple values in a reference. |
var myvariable = [1, ' Bob ', ' Steve ', ten]; The elements of the array are called only: myvariable[0] , myvariable[1] , and so on. |
| object |
object, basically everything in JavaScript is an object, and can be stored in a variable. Keep this in mind. |
var myvariable = document.queryselector (' H1 '); All of the above examples are objects. |
Undefined is a special class, typeof (undefined) output is defined
Null is summed up as a special class in the list, but the typeof (null) output is an object, how to determine whether it is null, the decision variable temp, see the following code:
[JavaScript]View Plaincopy
- if (temp&&typeof (temp) = = ="Object") {
- Temp is an array or an object
- }
So how to tell if a passed in parameter is an array, the TypeOf operator cannot judge an object or an array, and we need to determine his constructor, see the following code:
[JavaScript]View Plaincopy
- if (temp&&typeof (temp) = = =' object ' &&temp.constructor===array) {
- //temp is an array
- }
The above test will give false when the array is detected in a different frame or window, and the following detection may be more effective when the array is likely to be created in another frame.
[JavaScript]View Plaincopy
- if (temp&&typeof (temp) = = =' object ' &&typeof (temp.length) = = =' number ' &&! Temp.propertyenumerable (' length ')) {
- }
The arguments array is not an array, it is an object with a length member element. The above detection will recognize the arguments array as an array, which is sometimes the result you want, although arguments does not contain an array method. Anyway, If the Propertyiseumarable method is overwritten, the detection may still fail.
Excerpt from JavaScript essence and MDN
JavaScript notes Java basic data type < 0 >