|
This page contains all of the posts and discussion on MemeStreams referencing the following web page: When does 10 = 8?. You can find discussions on MemeStreams as you surf the web, even if you aren't a MemeStreams member, using the Threads Bookmarklet.
|
When does 10 = 8? by Acidus at 11:47 am EDT, Jun 27, 2007 |
In octal of course!
var x = 010;
alert(x); //displays 8
In JavaScript, Numeric Literals with leading 0's are treated as octal literals, unless the prefix is 0x, in which case its hex. |
|
RE: When does 10 = 8? by Hijexx at 10:48 am EDT, Jun 28, 2007 |
Acidus wrote: In octal of course!
var x = 010;
alert(x); //displays 8
In JavaScript, Numeric Literals with leading 0's are treated as octal literals, unless the prefix is 0x, in which case its hex.
Yeah, I remember when this first bit me in Perl. "WTF???" was my reaction. |
|
| |
RE: When does 10 = 8? by Acidus at 12:25 pm EDT, Jun 28, 2007 |
Hijexx wrote: Acidus wrote: In octal of course!
var x = 010;
alert(x); //displays 8
In JavaScript, Numeric Literals with leading 0's are treated as octal literals, unless the prefix is 0x, in which case its hex.
Yeah, I remember when this first bit me in Perl. "WTF???" was my reaction.
I got hit randomly generating number strings for alert boxes in XSS payloads. I used a JS interpreter on the response to confirm the XSS executed. I'd trap the popup box, and read the text but sometimes it would be different than what I sent. Octal literals were the reason. |
|
|
RE: When does 10 = 8? by Neoteric at 12:25 pm EDT, Jun 28, 2007 |
Acidus wrote: In octal of course!
var x = 010;
alert(x); //displays 8
In JavaScript, Numeric Literals with leading 0's are treated as octal literals, unless the prefix is 0x, in which case its hex.
This is exactly the way it is in C. --timball |
|
|
|