- #2,171
- 14,835
- 8,186
An oldie but goodie
In JavaScript it's your age plus 0.000000000001567.Take your age, add three, then subtract three. That's your age.
var a="123"
var b=a+3
var c=b-3
document.write(c)
--> 1230
So + is defined for strings so 3 is cast to string and b gets the value "1233", but - isn't defined for strings so b gets cast to integer and c is 1230? That's nasty...mfb said:In JavaScript it's your age plus 0.000000000001567.
Or 10 times your age, if you take your age as string.
Code:var a="123" var b=a+3 var c=b-3 document.write(c) --> 1230
You hear about the guy who got fired from the calendar factory? He took a day off.pinball1970 said:I am afraid for the calendar..
It's days are numbered.
McKinsey was hired by the manufacturer. They found out, that costs could be reduced by a factor 1/364 if all calendar pages are printed with "Today".phinds said:You hear about the guy who got fired from the calendar factory? He took a day off.
Ibix said:So + is defined for strings so 3 is cast to string and b gets the value "1233", but - isn't defined for strings so b gets cast to integer and c is 1230? That's nasty...
I may take these jokes to the homework helper section, 'Explain why these are funny.'fresh_42 said:McKinsey was hired by the manufacturer. They found out, that costs could be reduced by a factor 1/364 if all calendar pages are printed with "Today".
pinball1970 said:I may take these jokes to the homework helper section, 'Explain why these are funny.'
I have one of these electronic calendars. If you hit the → key, it says "Tomorrow" and if you hit the ← key, it says "Yesterday".fresh_42 said:
Yes. JavaScript is full of these odd features.Ibix said:So + is defined for strings so 3 is cast to string and b gets the value "1233", but - isn't defined for strings so b gets cast to integer and c is 1230? That's nasty...
string=('b'+'a'+ + 'a' + 'a').toLowerCase()
produces "banana".!null+""+ +'a'
produces the string "trueNaN".I've used Javascript a few times and was aware that its type conversion was... interesting, but I hadn't realized quite how interesting.mfb said:JavaScript is full of these odd features.
Which, of course, implies that 95 = NaN in SI.DrGreg said:This reminds me of the time I saw a price ticket on a supermarket shelf which told me that the price of a product was 95p and the price per 100g was NaNp.
Or that the object for sale was a photon.kuruman said:Which, of course, implies that 95 = NaN in SI.
I suspect that 0+"95p" probably does equal NaN in Javascript...kuruman said:Which, of course, implies that 95 = NaN in SI.
How many psychologists does it take to change a lightbulb?etotheipi said:How many number theorists does it take to change a lightbulb?
Nobody knows the exact number, but it is believed to be an elegant prime.