Original text: dev. To/shafikshaon…

Translator: Front-end wisdom

Click “like” and then look, wechat search [Big Move the world] pay attention to this person without dACHang background, but with a positive attitude upward. In this paper, making github.com/qq449245884… Has been included, the article has been categorized, also organized a lot of my documentation, and tutorial materials.

Everyone said there was no project on your resume, so I found one and gave it away【 Construction tutorial 】.

There are many interesting things about using JS. Even though engineers deal with it every day, there are still some languages that haven’t been developed. This section introduces some JS features that you might not expect.

NaN is a number type

NaN is a number type. Moreover, NaN is not equal to itself. NaN is not really equal to anything, and checking whether a variable isNaN can be done using the isNaN() method.

> typeof(NaN)
"number"

> NaN === NaN
false
Copy the code

Null is an object

Null is an object. Sounds strange! For? But it’s true.

> typeof(null)
"object"
Copy the code

In this case, NULL means there is no value. Therefore, NULL should not be an instance of Object.

> null instanceof Object
false    
    
Copy the code

Undefined can be defined

Undefined is not a reserved keyword in JS. You can specify a value for it without error. If you declare a variable without assigning a value, it defaults to undefined

> var some_var;
undefined
> some_var == undefined
true
> undefined = 'i am undefined'   
Copy the code

0.1 + 0.2 does not equal to 0.3

In JavaScript, 0.1 +0.2 == 0.3 returns false. The fact is that javascript stores floating point numbers as binary.

> 0.1 + 0.2
0.30000000000000004
> 0.1 + 0.2 == 0.3
false    
Copy the code

Math. Max () than Math. Min ()

The fact that math.max () > math.min () returns false looks wrong, but it is actually correct.

If no arguments are passed to min() or Max (), it returns the following values.

> Math.max()
-Infinity
> Math.min()
Infinity    
Copy the code

018 minus 045 is minus 19

In JavaScript, the prefix 0 converts any number to octal. However, eight is not used in octal, and any number containing eight is silently converted to a regular decimal number.

> 018-045-19Copy the code

Therefore, 018-019 is actually equal to the decimal expression 18-37, because 045 is octal, but 018 is decimal.

Functions can be self-executing

Simply create a function and call it as soon as other functions are called, using the () syntax

> (function() { console.log('I am self executing'); }) (); I am self executingCopy the code

The placement of the parentheses

The 'return' statement returns nothing if there is nothing behind it. In fact, JS 'return' adds a '; `. > function foo() { return { foo: 'bar' } } > foo(); undefined > function foo() { return { foo: 'bar' } } > foo(); {foo: "bar"}Copy the code

There are no integer data types

In JS, there are no int data types. All numbers are of the Number type. It actually stores the floating-point value of an int in memory.

The sort() function automatically converts types

The sort() function automatically converts values to strings, which can cause strange things to happen.

> [1,5,20,10].sort()
(4) [1, 10, 20, 5]
Copy the code

However, it can be solved by comparison:

,5,20,10 > [1]. Sort (function (a, b) {return a - b}); (4) [1, 5, 10, 20]Copy the code

The sum of arrays and objects

>! + [] +!!!!! [] +!!!!! [] +!!!!! [] +!!!!! [] +!!!!! [] +!!!!! [] +!!!!! [] +!!!!! [] 9 > {} + [] 0 > [] + {} "[object Object]" > [] + [] "" > {} + {} "[object Object][object Object]" > {} + [] == [] + {} trueCopy the code

communication

This article is updated every week, you can search wechat “big move the world” for the first time to read and urge more (one or two earlier than the blog hey), this article GitHub github.com/qq449245884… It has been included and sorted out a lot of my documents. Welcome Star and perfect. You can refer to the examination points for review in the interview.