Article From:
"use strict"
var a = 2;
var qq = function() {
    var a = 1;
  1. Who is the this pointing to here? Why not windows?
  2. In the “use strict” mode, why do we use the following naming function to report errors? How to solve it?

    “use strict”
    var a= 2;
    function qq(){
    var a = 1;


Answer 0:

1、Strict mode points to undefined, not window, because strict mode does not automatically bind the direction of this with apply.
2、And it’s not going to be wrong. Is the reason why you’re wrong? Is the double quotation mark outside your strict mode the reason why it’s Chinese…?

Answer 1:

1,The this here is window.
2,“use strict”It’s a strict mode.
“In strict mode, the value passed to a function through this will not be coerced into an object. For a normal function, this is always an object: whether it is called as an object, or when a function is called with a Boolean value, string, or number, it is called inside the function.This encapsulated as an object; still use undefined or null to call the global object represented by the functional this (using call, apply, or bind methods to specify a certain this). The process of automatically transforming objects into objects is not only a kind of nature.Energy wastage, and exposing global objects in browsers, can also be a security risk, because global objects provide access to functions that must be restricted by so-called secure JavaScript environments. So for a function that opens strict mode, the specified this is no longer encapsulated as a pair.Image, and if it does not specify this, its value is undefined “.

Answer 2:
  1. thisPointing to undefined. Because it’s a strict mode. If you remove the first line, it is window.
  2. I didn’t make any mistakes here, except for your double quotes.
Answer 3:
  1. thisPoint to undefined. Under strict mode, the global scope is not window, it is undefined.
  2. No mistake
Answer 4:

Thank you. I made a mistake myself.

Link of this Article: This pointing problem in JS

Leave a Reply

Your email address will not be published. Required fields are marked *