Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 138192

This in codesandbox.io, use strict and not use strict

$
0
0

i am new to js. and I don’t really understand how this works. I have a few examples and they work differently in codesandbox.io, use strict and not use strict.

example 1

var obj = {
    id: "awesome",
    cool: function coolFn() {
        console.log( this);
    }
};

var id = "not awesome";

obj.cool(); 

setTimeout( obj.cool, 100 ); 

in codesandbox Object {id: "awesome", cool: function coolFn()}, null.

in use strict {id: "awesome", cool: ƒ},Window{...}.

in not use strict {id: "awesome", cool: ƒ},Window{...}.

example 2

var obj = {
  id: "awesome",
  cool: () => {
    console.log(this);
  }
};

var id = "not awesome";

obj.cool();

setTimeout(obj.cool, 100);

in codesandbox undefined, undefined.

in use strict Window{...},Window{...}.

in not use strict Window{...},Window{...}.

who can explain what is happening in my examples ?


Viewing all articles
Browse latest Browse all 138192

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>