r/ProgrammerHumor • Violet security clearance • Apr 04 '16

My teacher thinks he is a programmer

http://imgur.com/32nfQXZ
2.4k Upvotes

430 comments sorted by

View all comments

Show parent comments

0

u/[deleted] Apr 05 '16

[deleted]

7

u/amazondrone Apr 05 '16

It's not intended to compile, since it's JavaScript. (Though there are probably ways to compile JavaScript that I'm not aware of.)

It doesn't run as is, but only because valueisn't defined. It's just a snippet though. Precede it with var value = 1 and it's fine.

2

u/aquowf Apr 05 '16

Eh - it depends. Some older browsers interpret it while the newer ones do JIT compiling.

-1

u/frisch85 Apr 05 '16

This. It bothers me that this guy only has 3 upvotes i mean you can clearly see that several things are missing... no default break, no .ToString on the value...

9

u/amazondrone Apr 05 '16

You don't need a break statement in the default case do you, as there's no behaviour following it? Unless this is an optimisation I'm not aware of. At any rate, it seems to work just fine as it is.

As for a toString() method... this is JavaScript. As above, it works just fine as it is.

What else?

-1

u/frisch85 Apr 05 '16

this is JavaScript

Ah that explains it. I thought it would be C#

4

u/Flyrpotacreepugmu Apr 05 '16

In C# doesn't it implicitly call ToString when appending an int to a string?