Like the baby please click attention, attention to the author does not get lost oh ~

Note: individual difficult to understand my drawing analysis, simple, easy to understand my text elaborated oh ~

Interview question 1: **
console.log([]==false) console.log(! []==false) Copy code Copy codeCopy the code

Resolution:

1. If two types are different, he has his own set of standards: object and string comparison is object to string, object == Boolean, both converted to numbers.
Object conversion to a number (implicit conversion) : toString is converted to a string before toString is converted to a number.
Array to number: []-> “->0 (empty array to string is empty string, empty string to number is 0)
[].valueof () : [].toString() : [].tostring () : [].tostring () : [].tostring ()
False converts to the number 0, and true converts to the number 1
2. Priority ratio of == = sign in js! Low priority
! [] converts an array to a Boolean type and inverts it, because only five values, ‘0, NaN, null, undefined, and empty string’, will be Boolean FALSE, the rest will be TRUE, [] is not the five values, so convert to TRUE! Is true or false

2. Interview Questions:

let res = parseFloat('left:200px'); if(res===200){ alert(200); }else if(res===NaN){ alert(NaN); }else if(typeof res==='number'){ alert('number'); }else{} Copy code Copy codeCopy the code

Resolution:

ParseInt mechanism: Search for a valid numeric character starting with the first character to the left of the string. (Stop looking for an invalid numeric character, regardless of whether there are more numeric characters to follow, and convert any found valid numeric characters to numbers. If none is found, the result is NaN(parseFloat recognizes one more decimal point than it does).
So res is NaN, because NaN! ==NaN(principle in memory live address is different);

Because NaN is a non-number, but it is of type Number, the result is’ Number ‘not Number

Why strings? Because alert and document output are strings

! [](https://p1-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/545bcea5cd7747f48dba573e9311034f~tplv-k3u1fbpfcp-zoom-1.image)

Interview question 3.

var a={}, b='0', c=0; a[b]='123'; a[c]='568'; console.log(a[b]); Copy code Copy codeCopy the code

Answer: 568

Interview question 4:

var a={}, b=Symbol('1'), c=Symbol('1'); a[b]='1'; a[c]='2'; console.log(a[b]); Copy code Copy codeCopy the code

Answer: 1.

The Symbol creates a unique value

Interview question 5:

var a={}, b={n:'1'}, c={m:'2'}; a[b]='11'; a[c]='2'; console.log(a[b]); var a = {n: 1}; var b = a; a.x = a = {n: 2}; console.log(a.x); console.log(b); Copy code Copy codeCopy the code

The answer:

2

undefined

{n: 1, x: {… }}

Resolution:

a[b]=’11’; =>a[object Object]=’11’

a[c]=’2′; =>a[object Object]=’2′

The latter overwrites the former, so console.log(a[b]); Is 2

Interview question 6:

let a=12; let b=13; function func(){ let a=1; let b=2; } console.log(a,b) Copy code Copy codeCopy the code

原 文 : Uncaught SyntaxError: Identifier ‘a’ has already been declared

Interview question 7:

function Func(x, y) { let total = x + y; this.result = total; this.say = function () {}; } let f1 = new Func(10, 20); console.log(f1); console.log(f1.total); console.log(f1.result); let f2 = new Func(); console.log(f2); Console. log('say' in f1) Copies code Copies codeCopy the code

The answer:

Func {result: 30, say: ƒ}

undefined

Func {result: NaN, say: ƒ}

true

Drawing helps you understand the principle:

Question 8 :(baidu second surface) implement the function fn, so that it has the following functions

Let res = fn (1, 2) (3); console.log(res); //=>6 1+2+3 Copy code Copy codeCopy the code

A. the b. the C. the D. the

function compose(... Funcs) {// funcs: Store sequentially executed functions (array) =>[fn1, fn3, fn2, fn4] return function anonymous(... >[20] if (funcs.length === 0) return args; // funcs.length === 0; if (funcs.length === 1) return funcs[0](... args); Return funcs.reduce((N, func) => {// The value of N for the first time: the argument func for the first function is the first function // the value of N for the second time: the value returned by the last func execution, As an argument to the next function: return array.isarray (N)? func(... N) : func(N); }, args); }; }let res = compose(fn1, fn3, fn2, fn4)(20, 30); //compose(fn1, fn3, fn2, fn4) is executed, and its return value is followed by (20,30)console.log(res); Copy code Copy codeCopy the code

Interview question 9: Implement function fn with the following functions

One of the most important concepts in functional programming is function composition, which is essentially connecting functions that process data like pipes, and then passing the data through the pipes to get the final result. For example, const add1 = (x) => x + 1; const mul3 = (x) => x * 3; const div2 = (x) => x / 2; div2(mul3(add1(add1(0)))); //=>3 For compose, we can construct a compose function that takes any number of functions as arguments (each of which takes a single argument), and then compose returns a function that does the following:  const operate = compose(div2, mul3, add1, Div2 (mul3(add1(add1(0)))))) //=> div2(mul3(add1(add1(2))))) Compose (f, g, h)(x) : compose(f, g, h)(x) for composeCopy the code

Answer:

*/ const fn1 = (x, y) => x + y + 10; /* * compose: const fn1 = (x, y) => x + y + 10; const fn2 = (x) => x - 10; const fn3 = (x) => x * 10; const fn4 = (x) => x / 10; // let res = fn4(fn2(fn3(fn1(20)))); // console.log(res); function compose(... Funcs) {// funcs: Store sequentially executed functions (array) =>[fn1, fn3, fn2, fn4] return function anonymous(... >[20] if (funcs.length === 0) return args; // funcs.length === 0; if (funcs.length === 1) return funcs[0](... args); Return funcs.reduce((N, func) => {// The value of N for the first time: the argument func for the first function is the first function // the value of N for the second time: the value returned by the last func execution, As an argument to the next function: return array.isarray (N)? func(... N) : func(N); }, args); }; } let res = compose(fn1, fn3, fn2, fn4)(20, 30); //compose(fn1, fn3, fn2, fn4) is executed, and its return value is followed by (20,30) console.log(res); Copy code Copy codeCopy the code
This is the interview question of my friends, colleagues and classmates who went to Dachang. I have summarized it, and there are many more to summarize, and I will continue to summarize it later
** Stay tuned for (2) ~**