By Mark A. Translator: Front-end tips source: Dev


In this paper,GitHub Github.com/qq449245884…Has included more categories of previous articles, as well as a lot of my documentation and tutorial material. Welcome Star and Perfect, you can refer to the examination points for review in the interview, I hope we can have something together.

List of questions

  • 1. What is the difference between undefined and null?
  • 2. What can the && operator do
  • 3. | | operators to do
  • 4. Is using the + or unary addition operator the fastest way to convert a string to a number?
  • 5. What is DOM?
  • 6. What is event propagation?
  • 7. What is event bubbling?
  • 8. What is event capture?
  • 9. What’s the difference between the event.preventDefault() and event.stopPropagation() methods?
  • 10. How do I know if the event.preventDefault() method is used on the element?
  • 11. Why does obj.someprop.x cause an error?
  • 12. What is Event.target?
  • 13. What is event.currenttarget?
  • 14. What’s the difference between == and ==?
  • 15. Why return false when comparing two similar objects in JS?
  • 16.!!!!! What can an operator do?
  • 17. How do I evaluate multiple expressions in a single line?
  • 18. What is promotion?
  • 19. What is scope?
  • What is a closure?
  • 21. What are imaginary values in JavaScript?
  • 22. How do I check whether a value is virtual?
  • 23. What is ‘use strict’ for?
  • 24. What is this value in JavaScript?
  • 25. What is the prototype of the object?

1. What is the difference between undefined and null?

Before we understand the difference between undefined and NULL, let’s look at their similarities.

They belong to the seven basic types of JavaScript.

 let primitiveTypes = ['string'.'number'.'null'.'undefined'.'boolean'.'symbol'.'bigint'];

Copy the code

They are virtual and can be Boolean(value) or!! Value When converted to a Boolean value, the value is false.

console.log(!!null); // false

console.log(!!undefined); // false



console.log(Boolean(null)); // false

console.log(Boolean(undefined)); // false

Copy the code

Now let’s see what the difference is.

Undefined is the default value for variables that do not specify a specific value, functions that do not return an explicit value, such as console.log(1), and properties that do not exist in objects. These JS engines assign undefined to them.

let _thisIsUndefined;

const doNothing = (a)= > {};

const someObj = {

  a : "ay".

  b : "bee".

  c : "si"

};



console.log(_thisIsUndefined); // undefined

console.log(doNothing()); // undefined

console.log(someObj["d"]); // undefined

Copy the code

Null is “a value that does not represent any value”. Null is a value that has been explicitly defined for a variable. In this example, we get the null value when the fs.readfile method does not raise an error.

fs.readFile('path/to/file'.(e,data)= > {

   console.log(e); //Print when no errors occurnull

   if(e){

     console.log(e);

   }

   console.log(data);

 });

Copy the code

When comparing null and undefined, we get true when we use == and false when we use === :

 console.log(null= =undefined); // true

 console.log(null= = =undefined); // false

Copy the code

2. What can the && operator do

Am&, also called logical and, finds the first virtual-valued expression in its operands and returns it, or returns the last truth-valued expression if no virtual-valued expression is found. It uses a short circuit to prevent unnecessary work.

console.log(false && 1 && []); // false

console.log("" && true && 5); / / 5

Copy the code

useifstatements

const router: Router = Router();



router.get('/endpoint'.(req: Request, res: Response)= > {

   let conMobile: PoolConnection;

   try {

      //do some db operations

   } catch (e) {

   if (conMobile) {

    conMobile.release();

   }

  }

});

Copy the code

use&&The operator

const router: Router = Router();



router.get('/endpoint'.(req: Request, res: Response)= > {

  let conMobile: PoolConnection;

  try {

     //do some db operations

  } catch (e) {

    conMobile && conMobile.release()

  }

});

Copy the code

3. | | operators to do

| | also call or logic or, find the first true value in its operands expressions and returns it. This also uses a short circuit to prevent unnecessary work. It is used to initialize default parameter values in functions prior to supporting ES6 default function parameters.

console.log(null || 1 || undefined); / / 1



function logName(name{

  var n = name || "Mark";

  console.log(n);

}



logName(); // "Mark"

Copy the code

4. Is using the + or unary addition operator the fastest way to convert a string to a number?

According to the MDN documentation, + is the fastest way to convert a string to a number because it does nothing if the value is already a number.

5. What is DOM?

DOM stands for document Object Model and is an interface (API) for HTML and XML documents. When the browser first reads (parses) an HTML document, it creates a large object, a very large object based on an HTML document, called the DOM. It is a tree structure modeled from an HTML document. The DOM is used to interact with and modify the DOM structure or specific elements or nodes.

Suppose we have an HTML structure like this:


       

<html lang="en">



<head>

   <meta charset="UTF-8">

   <meta name="viewport" content="Width = device - width, initial - scale = 1.0">

   <meta http-equiv="X-UA-Compatible" content="ie=edge">

   <title>Document Object Model</title>

</head>



<body>

   <div>

      <p>

         <span></span>

      </p>

      <label></label>

      <input>

   </div>

</body>



</html>

Copy the code

The equivalent DOM looks like this:

)

The Document object in JS represents the DOM. It gives us a number of methods that we can use to select elements to update their content, and so on.

6. What is event propagation?

When an event occurs on a DOM element, it does not happen exactly on that element. In the “bubble phase,” events bubble or propagate up to the parent, grandparent, grandparent, or parent until they reach the window; In the capture phase, the event starts from the window and fires down the element event or event.target.

There are three stages of event propagation:

  1. Capture phase – Events start at the window and work down to each element until the target element is reached.

  2. Target phase – The event has reached the target element.

  3. Bubble phase – Events bubble up from the target element and then up to each element until they reach the Window.

clipboard.png

7. What is event bubbling?

When an event occurs on a DOM element, it does not happen exactly on that element. In the bubble phase, the event bubbles, or the event occurs in its parent, grandparent, grandparent, until it reaches the window.

Suppose you have the following HTML structure:

<div class="grandparent">

  <div class="parent">

    <div class="child">1</div>

  </div>

</div>

Copy the code

Corresponding JS code:

function addEvent(el, event, callback, isCapture = false{

  if(! el || ! event || ! callback ||typeofcallback ! = ='function'return;

  if (typeof el === 'string') {

    el = document.querySelector(el);

  };

  el.addEventListener(event, callback, isCapture);

}



addEvent(document.'DOMContentLoaded', () = > {

  const child = document.querySelector('.child');

  const parent = document.querySelector('.parent');

  const grandparent = document.querySelector('.grandparent');



  addEvent(child, 'click'.function (e{

    console.log('child');

  });



  addEvent(parent, 'click'.function (e{

    console.log('parent');

  });



  addEvent(grandparent, 'click'.function (e{

    console.log('grandparent');

  });



  addEvent(document.'click'.function (e{

    console.log('document');

  });



  addEvent('html'.'click'.function (e{

    console.log('html');

  })



  addEvent(window.'click'.function (e{

    console.log('window');

  })



});

Copy the code

The addEventListener method has a third optional argument, useCapture, which defaults to false and events occur during the bubble phase or, if true, during the capture phase. If you click on the Child element, it records Child, parent, Grandparent, HTML, Document, and Window, respectively, on the console, which is the event bubbling.

8. What is event capture?

When an event occurs on a DOM element, it does not happen exactly on that element. In the capture phase, the event starts at the window and goes all the way to the element that triggered the event.

Suppose you have the following HTML structure:

<div class="grandparent">

  <div class="parent">

    <div class="child">1</div>

  </div>

</div>

Copy the code

Corresponding JS code:

function addEvent(el, event, callback, isCapture = false{

  if(! el || ! event || ! callback ||typeofcallback ! = ='function'return;

  if (typeof el === 'string') {

    el = document.querySelector(el);

  };

  el.addEventListener(event, callback, isCapture);

}



addEvent(document.'DOMContentLoaded', () = > {

  const child = document.querySelector('.child');

  const parent = document.querySelector('.parent');

  const grandparent = document.querySelector('.grandparent');



  addEvent(child, 'click'.function (e{

    console.log('child');

  });



  addEvent(parent, 'click'.function (e{

    console.log('parent');

  });



  addEvent(grandparent, 'click'.function (e{

    console.log('grandparent');

  });



  addEvent(document.'click'.function (e{

    console.log('document');

  });



  addEvent('html'.'click'.function (e{

    console.log('html');

  })



  addEvent(window.'click'.function (e{

    console.log('window');

  })



});

Copy the code

The addEventListener method has a third optional argument, useCapture, which defaults to false and events occur during the bubble phase or, if true, during the capture phase. If you click on the Child element, it prints Window, Document, HTML, grandparent, andparent on the console, respectively, which is event capture.

9. What’s the difference between the event.preventDefault() and event.stopPropagation() methods?

The event.preventDefault() method prevents the element’s default behavior. If used within a form element, it blocks submission. If used in an anchor element, it prevents navigation. If used in a context menu, it prevents it from being displayed or displayed. The event.stopPropagation() method is used to prevent further propagation of current events in the capture and bubble phases.

10. How do I know if the ‘event.preventdefault ()’ method is used on the element?

We can use the Event.DefaultSpoiled property in the event object. It returns a Boolean that indicates whether the event.preventDefault() is called on the particular element.

11. Why does this code ‘obj.someprop.x’ cause an error?

const obj = {};

console.log(obj.someprop.x);

Copy the code

Obviously, since we are trying to access the X property in the someprop property and someprop is not in the object, the value is undefined. Remember that the object itself does not have an attribute, and its stereotype defaults to undefined. Because undefined does not have an attribute x, attempts to access it will result in an error.

12. What is Event.target?

Simply put, event.target is the element that produces the event or that triggers the event.

Suppose you have the following HTML structure:

<div onclick="clickFunc(event)" style="text-align: center; margin:15px;

border:1px solid red; border-radius:3px;"
>


    <div style="margin: 25px; border:1px solid royalblue; border-radius:3px;">

        <div style="margin:25px; border:1px solid skyblue; border-radius:3px;">

          <button style="margin:10px">

             Button

          </button>

        </div>

    </div>

 </div>

Copy the code

The JS code is as follows:

function clickFunc(event{

  console.log(event.target);

}

Copy the code

If we click button, even if we append the event to the outermost div, it will print the Button label, so we can conclude that event.target is the element that triggers the event.

13. What is event.currenttarget??

Event.currenttarget is the element on which we explicitly attach an event handler.

Suppose you have the following HTML structure:

<div onclick="clickFunc(event)" style="text-align: center; margin:15px;

border:1px solid red; border-radius:3px;"
>


    <div style="margin: 25px; border:1px solid royalblue; border-radius:3px;">

        <div style="margin:25px; border:1px solid skyblue; border-radius:3px;">

          <button style="margin:10px">

             Button

          </button>

        </div>

    </div>

 </div>

Copy the code

The JS code is as follows:

function clickFunc(event{

  console.log(event.currentTarget);

}

Copy the code

If we click button, even if we click the button, it will print the outermost DIV tag. In this example, we can conclude that event.currenttarget is the element to attach the event handler.

14. What’s the difference between == and ==?

== is used for general comparison, === is used for strict comparison, == can convert data types when comparing, === strict comparison, if the type does not match flase is returned.

Let’s take a look at this brother:

Coercion is the process of converting a value to another type. In this case, == performs implicit coercion. Before comparing two values, == needs to perform some rules.

Suppose we want to compare x equals y.

  1. ifxandyIs of the same type, JS will be replaced= = =Operator to compare.
  2. ifxfornull.yforundefined, the returntrue.
  3. ifxforundefinedandyfornull, the returntrue.
  4. ifxIs of typenumber.yIs of typestring, then returnx == toNumber(y).
  5. ifxIs of typestring.yIs of typenumber, then returntoNumber(x) == y.
  6. ifxFor the type isboolean, the returntoNumber(x)== y.
  7. ifyFor the type isboolean, the returnx == toNumber(y).
  8. ifxisstring,symbolornumberAnd theyisobjectType, returnsx == toPrimitive(y).
  9. ifxisobject.yisstring.symbolIt returnstoPrimitive(x) == y.
  10. The rest goes backfalse

Note: toPrimitive first uses the valueOf method in the object, and then the toString method to get the original valueOf the object.

Let me give you an example.

x y x == y
5 5 true
1 ‘1’ true
null undefined true
0 false true
‘1, 2,’ [1, 2] true
‘[object Object]’ {} true

These examples all return true.

The first example satisfies condition 1 because x and y have the same type and value.

The second example meets condition 4 and converts y to a number before comparing.

The third example satisfies condition 2.

The fourth example satisfies condition 7 because y is Boolean.

The fifth example meets condition 8. The array is converted to a string using the toString() method, which returns 1,2.

The last example satisfies condition 8. An object is converted to a string using the toString() method, which returns [Object object].

x y x === y
5 5 true
1 ‘1’ false
null undefined false
0 false false
‘1, 2,’ [1, 2] false
‘[object Object]’ {} false

If the === operator is used, all comparisons except the first example will return false because they are of different types, and the first example will return true because both have the same type and value.

For more rules, please refer to my previous article:

I was confused about the conversion process of equality and congruence operators in JS until I had this algorithm

15. Why return false when comparing two similar objects in JS?

Take a look at the following example:

let a = { a1 };

let b = { a1 };

let c = a;



console.log(a === b); // Print false, even if they have the same property

console.log(a === c); // true

Copy the code

JS compares objects and primitive types in different ways. In primitive types, JS compares them by value, while in objects, JS compares variables by reference or by an address in memory where they are stored. This is why the first console.log statement returns false and the second console.log statement returns true. A and C have the same reference address, while A and B do not.

16.!!!!! What can an operator do?

!!!!! The operator can cast the value on the right to a Boolean, which is an easy way to convert a value to a Boolean.

console.log(!!null); // false

console.log(!!undefined); // false

console.log(!!' '); // false

console.log(!!0); // false

console.log(!!NaN); // false

console.log(!!' '); // true

console.log(!! {});// true

console.log(!! []);// true

console.log(!!1); // true

console.log(!! [].length);// false

Copy the code

17. How do I evaluate multiple expressions in a single line?

Multiple expressions can be evaluated on a single line using the comma operator. It evaluates from left to right and returns the value of the last item or operand on the right.

let x = 5;



x = (x++ , x = addFive(x), x *= 2, x -= 5, x += 10);



function addFive(num{

  return num + 5;

}

Copy the code

The result above ends up with an x value of 27. First, we increase the value of x to 6, then call the function addFive(6) and pass 6 as an argument and reassign the result to X, where x has a value of 11. After multiplying the current value of x by 2 and assigning it to X, the updated value of x is 22. Then, subtract 5 from the current value of x and assign the result to x, where the updated value is 17. Finally, we increase the value of x by 10, and then assign the updated value to x, which ends up being 27.

18. What is promotion?

Promotion is the term used to describe moving variables and functions to the top of their (global or function) scope.

To understand promotion, you need to understand the execution context. The execution context is the “code environment” that is currently executing. The execution context has two phases: compilation and execution.

Compile – At this stage, JS referrals take all function declarations and promote them to the top of their scope so that we can reference them later and get all variable declarations (declared using the var keyword), and provide them with a default value: undefined.

Execute – In this phase, it assigns values to previously promoted variables and executes or calls functions (methods in objects).

Note: Only variables declared using var or function declarations are promoted. In contrast, function expressions or arrow functions, let and const variables are not promoted.

Assume that in the global use domain, there is code like this:

console.log(y);

y = 1;

console.log(y);

console.log(greet("Mark"));



function greet(name){

  return 'Hello ' + name + '! ';

}



var y;

Copy the code

Undefined,1, Hello Mark! .

The above code actually looks like this at compile time:

function greet(name{

  return 'Hello ' + name + '! ';

}



var y; // Default value undefined



// Wait for the "compile" phase to complete, then start the "execute" phase



/ *

console.log(y);

y = 1;

console.log(y);

console.log(greet("Mark"));

* /


Copy the code

Once the compile phase is complete, it starts the execution phase calling the method and assigning values to variables.

function greet(name{

  return 'Hello ' + name + '! ';

}



var y;



//start "execution" phase



console.log(y);

y = 1;

console.log(y);

console.log(greet("Mark"));

Copy the code

19. What is scope?

A scope in JavaScript is an area where we can effectively access a variable or function. JS has three types of scope: global scope, function scope and block scope (ES6).

  • Global scope – Variables or functions declared in the global namespace are in the global scope, so they can be accessed anywhere in the code.
//global namespace

var g = "global";



function globalFunc(){

  function innerFunc(){

    console.log(g); // can access "g" because "g" is a global variable

  }

 innerFunc();

}  

Copy the code
  • Function scope — Variables, functions, and parameters declared in a function can be accessed inside the function, but not outside the function.
function myFavoriteFunc(a{

  if (true) {

    var b = "Hello " + a;

  }

  return b;

}



myFavoriteFunc("World");



console.log(a); // Throws a ReferenceError "a" is not defined

console.log(b); // does not continue here

Copy the code
  • Block scope– in the block{}Variables declared in (Let, const) can only be accessed in it.
 function testBlock(){

   if(true) {

     let z = 5;

   }

   return z; 

 }



 testBlock(); // Throws a ReferenceError "z" is not defined

Copy the code

A scope is also a set of rules for finding variables. If the variable does not exist in the current scope, it looks up and searches the outer scope. If the variable does not exist, it looks again until it reaches the global scope. If it finds it, it can use it, otherwise it raises an error.

   /* Scope chain



Internal scope -> external scope -> global scope

* /




  // Global scope

  var variable1 = "Comrades";   

  var variable2 = "Sayonara";



  function outer(){

  // External scope

    var variable1 = "World";

    function inner(){

    // Inner scope

      var variable2 = "Hello";

      console.log(variable2 + "" + variable1);

    }

    inner();

  }  

  outer(); // Hello World

Copy the code

What is a closure?

This is probably the most difficult question of all, because closures are a controversial topic, so here’s a personal one.

A closure is a function that, when declared, remembers the current scope, the parent function scope, and references to variables and parameters in the parent function scope, up to the global scope on the scope chain. Basically, a closure is a scope created when the function is declared.

Take a look at a small example:

   // Global scope

   var globalVar = "abc";



   function a(){

     console.log(globalVar);

   }



   a(); // "abc"

Copy the code

In this example, when we declare a function, the global scope is part of the A closure.

clipboard.png

The reason the globalVar variable has no value in the diagram is that its value can change depending on where and when function A is called. But in the example above, the globalVar variable has the value ABC.

Let’s look at a more complicated example:

var globalVar = "global";

var outerVar = "outer"



function outerFunc(outerParam{

  function innerFunc(innerParam{

    console.log(globalVar, outerParam, innerParam);

  }

  return innerFunc;

}



const x = outerFunc(outerVar);

outerVar = "outer-2";

globalVar = "guess"

x("inner");

Copy the code
clipboard.png

It printed guess Outer inner.

When we call outerFunc and assign the innerFunc function with the return value to variable X, outerParam keeps the outer value even if we assign the outerVar variable outer-2 because the reallocation happens after outerFunc is called, And when we call the outerFunc function, it looks for the value of outerVar in the scope chain, which will be “outer”.

Now, when we call the X variable that references innerFunc, innerParam will have an inner value, because that’s the value we passed in the call, and the globalVar variable will have a guess value, because we assigned a new value to globalVar before calling the X variable.

The following example demonstrates the error of not understanding closures well:

const arrFuncs = [];

for(var i = 0; i < 5; i++){

  arrFuncs.push(function (){

    return i;

  });

}

console.log(i); // i is 5



for (let i = 0; i < arrFuncs.length; i++) {

  console.log(arrFuncs[i]()); // Print all 5

}

Copy the code

This code does not work due to closures. The var keyword creates a global variable, the global variable I that is returned when we push a function. So when we call one of these functions in that array after the loop, it prints 5, because we get the current value of I is 5, and we can access it because it’s a global variable.

Because the closure keeps a reference to a variable rather than its value when it creates it. We can use IIFES or let instead of var declarations.

21. What are imaginary values in JavaScript?

 const falsyValues = [' '.0.null.undefined.NaN.false];

Copy the code

Simply put, an imaginary value is a value that becomes false when converted to a Boolean value.

22. How do I check whether a value is virtual?

Use Boolean functions or!! Operator.

23. What is ‘use strict’ for?

“Use strict” is an ES5 feature that puts our code in strict mode within a function or entire script. Strict mode helps us avoid bugs early in the code and adds restrictions to it.

Some limitations of strict mode:

  1. Variables must be declared before being used
  2. Function arguments cannot have attributes of the same name; otherwise, an error is reported
  3. You can’t usewithstatements
  4. Cannot assign a value to a read-only attribute, otherwise an error is reported
  5. Octal numbers cannot be represented with the prefix 0, otherwise an error is reported
  6. You cannot delete attributes that cannot be deleted; otherwise, an error is reported
  7. Cannot delete variablesdelete prop, an error is reported, and only attributes can be deleteddelete global[prop]
  8. evalYou cannot introduce variables in its outer scope
  9. evalandargumentsCannot be reassigned
  10. argumentsDoes not automatically reflect changes in function parameters
  11. You can’t usearguments.callee
  12. You can’t usearguments.caller
  13. banthisPointing to a global object
  14. You can’t usefn.callerandfn.argumentsGets the stack of function calls
  15. Added reserved words (e.gprotected,staticandinterface)

The main objectives of the Strict Mode are as follows:

  1. Eliminate some unreasonable and inaccurate Javascript syntax, reduce some weird behavior;
  2. Eliminate some unsafe code operation, to ensure the safety of code operation;
  3. Improve the efficiency of the compiler, increase the running speed;
  4. Set the stage for future versions of Javascript.

24. What is the value of ‘this’ in JavaScript?

Basically, this refers to the value of the object on which the function is currently being executed or called. The value of this varies depending on the context in which we use it and where we use it.

const carDetails = {

  name: "Ford Mustang".

  yearBought: 2005.

  getName(){

    return this.name;

  },

  isRegistered: true

};



console.log(carDetails.getName()); // Ford Mustang

Copy the code

This is usually what we expect, because in the getName method we return this.name, and in this context this points to the carDetails object, which is currently the “owner” object of the executing function.

Now let’s do something weird:

var name = "Ford Ranger";

var getCarName = carDetails.getName;



console.log(getCarName()); // Ford Ranger

Copy the code

It prints Ford Ranger, which is strange because Ford Mustang is printed in the first console.log statement. The reason for this is that the getCarName method has a different “owner” object, the Window object. Declaring a variable using the var keyword in the global scope appends the same properties to the window object as the variable name. Remember, when “use strict” is not used, this refers to the window object in the global scope.

console.log(getCarName === window.getCarName); // true

console.log(getCarName === this.getCarName); // true

Copy the code

In this case, this and Window refer to the same object.

One way to solve this problem is to use the Apply and call methods in functions.

console.log(getCarName.apply(carDetails)); // Ford Mustang

console.log(getCarName.call(carDetails));  // Ford Mustang

Copy the code

The Apply and Call methods expect the first argument to be an object that is the value of this inside the function.

IIFE or immediately-executed function expressions, functions declared in global scope, anonymous functions in methods inside the object, and this of the internal function have default values that point to the window object.

   (function (){

     console.log(this);

}) ();// Prints the "window" object



   function iHateThis(){

      console.log(this);

   }



   iHateThis(); // Prints the "window" object



   const myFavoriteObj = {

     guessThis(){

        function getName(){

          console.log(this.name);

        }

        getName();

     },

     name'Marko Polo'.

     thisIsAnnoying(callback){

       callback();

     }

   };





   myFavoriteObj.guessThis(); // Prints the "window" object

   myFavoriteObj.thisIsAnnoying(function (){

     console.log(this); // Prints the "window" object

   });

Copy the code

If we want to get the value of the Name attribute (Marko Polo) in the myFavoriteObj object, there are two ways to solve this problem.

One is to store the this value in a variable.

const myFavoriteObj = {

 guessThis(){

  const self = this// Store this value in the self variable

  function getName(){

    console.log(self.name);

  }

  getName();

 },

 name'Marko Polo'.

 thisIsAnnoying(callback){

   callback();

  }

};

Copy the code

The second way is to use the arrow function

const myFavoriteObj = {

  guessThis(){

     const getName = (a)= > { 

       console.log(this.name);

     }

     getName();

  },

  name'Marko Polo'.

  thisIsAnnoying(callback){

   callback();

  }

};

Copy the code

Arrow functions do not have their own this. It copies the closed lexical scope this value, which in this case is outside the getName inner function, the myFavoriteObj object.

25. What is the prototype of the object?

Simply put, a prototype is a blueprint for an object. If it exists in the current object, it is used as a fallback for properties and methods. It’s a way of sharing properties and functionality between objects, which is at the heart of JavaScript implementation inheritance.

const o = {};

console.log(o.toString()); // logs [object Object]

Copy the code

Even if the O.tostring method does not exist in the O object, it does not raise an error, but returns the string [Object object]. When an object does not have an attribute, it looks at its prototype, and if it still does not, it looks to the prototype’s prototype, and so on, until it finds an attribute with the same attribute in the prototype chain. At the end of the prototype chain is Object.Prototype.

console.log(o.toString === Object.prototype.toString); // logs true

Copy the code

Because the space is too long, I will divide this series into three parts. We will see you in the next part.


The bugs that may exist after code deployment cannot be known in real time. In order to solve these bugs, I spent a lot of time on log debugging. Incidentally, HERE I recommend a good BUG monitoring tool Fundebug.

The original:

Dev. To/macmacky / 70…


communication

Dry goods series of articles summarized as follows, feel good point Star, welcome to add groups to learn from each other.

Github.com/qq449245884…

I am Xiaozhi, the author of the public account “Big Move the world”, and a lover of front-end technology. I will often share what I have learned to see, in the way of progress, mutual encouragement!

Pay attention to the public number, background welfare, you can see the welfare, you know.