This piece of code
eval(`
let a = 0;
function f() {}
function g() { a; }
console.log(f);
`);
works fine on Firefox 48.0 while causing Uncaught ReferenceError: f is not defined
on Google Chrome 52.0.2743.116 (64-bit).
It also works fine on Google Chrome if
eval
is not used, oreval
is surround with {}
, ora
is not referenced in g
, orlet
is changed to var
, or"use strict"
is added before the codeWhat's happening here?
Firefox Uses Less Memory Than Chrome Chrome creates extra processes for each page you open, each page has its own memory and its own copy. Instead, Firefox uses four content processes at any given time. Meaning that if you have 20 open tabs in Chrome, Chrome will use 20 processes and Firefox will only use four.
If Firefox previously worked but suddenly doesn't start, it may be due to some corrupt data in your settings. Uninstalling and reinstalling Firefox would not fix this problem because your settings are not removed on uninstall. To test to see if this is the problem, use the Profile Manager to create a new profile.
If you're looking for the best browser for Android, the two are great options. Chrome is a faster and more full-featured browser for everyday use, but many will prefer Firefox for its privacy and security.
Switching from Google Chrome to Firefox is easy and risk-free! Firefox can automatically import your bookmarks, passwords, history, and other data from Chrome without deleting it or interfering with any of its settings. Give it a try.
Tweaking your example you can see what's happening, and while the command is a bit contradictory, it looks like a bug. Define a as a function and log it instead of f, then have a look at the console. You'll see that a closure was created with a, f and g. Since a is referenced in g, and f and g should be visible to each other, it makes a bit of sense. But eval works in the global scope. So when you try to access them, you get undefined. It's like this closure cannot be accessed from anywhere.
Try:
eval('let a = function(){}; function f() {};function g(){a;};console.dir(a);');
You'll see this in the console:
<function scope>
Closure
a: function()
f: function f()
g: function g()
All your other cases make the situation clearer, and prevent the issue:
eval(`
"use strict";
let a = 0;
console.log(f);
function f(){
}
function g(){
a;
}
`);
Block-scoped declarations (let, const, function, class) not yet supported outside strict mode
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With