Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #32116 > unrolled thread
| Started by | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| First post | 2017-01-06 00:20 +0100 |
| Last post | 2017-01-06 00:20 +0100 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.javascript
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Why is eval( "05" ) a direct eval call in ECMAScript? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-01-06 00:20 +0100
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2017-01-06 00:20 +0100 |
| Subject | Re: Why is eval( "05" ) a direct eval call in ECMAScript? |
| Message-ID | <11687474.uLZWGnKmhe@PointedEars.de> |
Stefan Ram wrote:
> I am going to try to deduce why »eval( "05" )« is a
> direct call of eval in ECMAScript. […]
Because you are not using the return value of eval().
There are syntactical *and* a functional differences between each of the
following statements:
(function () {
var v = 42;
/* Modifies the local v;
creates global “v” property if “v” cannot be resolved */
eval("v = 23;");
console.log(v);
}());
(function () {
"use strict";
var v = 42;
/* Modifies the local v;
throws ReferenceError if “v” cannot be resolved */
eval("v = 23;");
console.log(v);
}());
(function () {
var v = 42;
/* Modifies the local v; can declare the local v if not declared */
eval("var v = 23;");
console.log(v);
}());
(function () {
"use strict";
var v = 42;
/* Declares and modifies the eval v, not the local v */
eval("var v = 23;");
console.log(v);
}());
(function () {
var v = 42;
/* Modifies the local v and x;
create global “v” property if “v” cannot be resolved */
var x = eval("v = 23;");
console.log(v);
}());
(function () {
"use strict";
var v = 42;
/* Modifies the local v and x;
throws ReferenceError if “v” cannot be resolved
*/
var x = eval("v = 23;");
console.log(v);
}());
(function () {
var v = 42;
/* Redeclares and modifies the local v */
var x = eval("var v = 23;");
console.log(v);
}());
(function () {
"use strict";
var v = 42;
/* Declares and modifies the eval v, not the local v */
var x = eval("var v = 23;");
console.log(v);
}());
Also, in your case the code does not work in strict mode because "05" is an
octal integer literal (produced by /OctalIntegerLiteral/):
| > eval("05")
| 5
|
| > (function () { "use strict"; eval("05"); }());
| Uncaught SyntaxError: Octal literals are not allowed in strict mode.(…)
|
| > (function () { var x = eval("05"); }());
| undefined
|
| (function () { "use strict"; var x = eval("05"); }());
| Uncaught SyntaxError: Octal literals are not allowed in strict mode.(…)
|
| > navigator.userAgent
| "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko)
| Chrome/53.0.2785.143 Safari/537.36"
(That is V8 JavaScript 5.3.332.47, see <chrome://version/>)
--
PointedEars
FAQ: <http://PointedEars.de/faq> | <http://PointedEars.de/es-matrix>
<https://github.com/PointedEars> | <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | Please do not cc me./Bitte keine Kopien per E-Mail.
Back to top | Article view | comp.lang.javascript
csiph-web