TheCrock Posted November 27, 2020 Share Posted November 27, 2020 (edited) I am very confused and I hope below makes sense. The first time I ran these two functions - the first called globalScope, returned 'window'in the console and the second called localScope, returned 'undefined' in the conole. let globalScope = () => console.log(this); globalScope(); let localScope = function(){ console.log(this); }; localScope(); I played a little with the second function and created a var called scope. var scope = this; then used console.log(scope); and it returned 'window'. Nice, So i cleared all of this and tried the two functions again and now they both return 'window' in the console. Am i mistaken? Did i reset something in Chrome? Shouldn't localScope return undefined again now. I am working from a book it says: ■■Note If you’re using ES5, you’ll need to force a function expression to use local scope by adding "use strict" as the function’s first line. So here is my REAL NEWBIE question. How do I know if I am using ES5 or ES6? Was the first time i ran the code using ES6 to get 'undefined' from localScope function - and now I am using ES5 and need to "use strict" I hope that makes sense because I am very confused. The book says that the localScope function would return 'undefined' in the console log and it did. But now it is returning 'window' in the console log. Thanks in advance Keith. Edited November 27, 2020 by TheCrock clarity Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.