Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

TorgoX (1933)

TorgoX
  sburkeNO@SPAMcpan.org
http://search.cpan.org/~sburke/

"Il est beau comme la retractilité des serres des oiseaux rapaces [...] et surtout, comme la rencontre fortuite sur une table de dissection d'une machine à coudre et d'un parapluie !" -- Lautréamont

Journal of TorgoX (1933)

Friday September 09, 2005
07:08 PM

Leaving out the semicolon in JavaScript

[ #26667 ]
Dear Log,

JavaScript is a relatively sane language, except for its stupid name, and except that at some point someone decided to add the "feature" of making the language forgive missing semicolons. Bad bad bad bad.

I urge everyone to avoid this "feature". The following examples should illustrate some of the lunacy that comes from leaving out semicolons:

function x (n) {
  throw
  ++n
}
x(100)
// Parses as throw(++n), so it throws an
//exception whose object is the number "101"

~~*~~

function x (n) {
  return
  ++n
}
x(100)
// Parses as return;++n, so it returns undefined.

~~*~~

function x (n) {
  return
  (++n)
}
x(100)
// Same as above.

~~*~~

function zoink (q) { alert(q||"?"); }
function x (n) {
  return zoink
}
x(100)
// Of course, parses as return zoink, returning
//  the 'zoink' function-object.

~~*~~

function zoink (q) { alert(q||"?"); }
function x (n) {
  return zoink
  ++n
}
x(100)
// Parses as return zoink;++n;, returning
//  the 'zoink' function-object.

~~*~~

function zoink (q) { alert(q||"?"); return 'huh!' }
function x (n) {
  return zoink
  (++n)
}
x(100)
// Parses as return zoink(++n);, actually calling
/   zoink, and returning 'huh!'.

~~*~~

function zoink (q) { alert(q||"?"); return 'huh!' }
function x (n) {
  zoink
  ++n
}
x(100)
// Parses as zoink;++n;, returning undefined (without
//  having called zoink, just having fetched its
//  object-value).

~~*~~

function zoink (q) { alert(q||"?"); return 'huh!' }
function x (n) {
  zoink
  (++n)
}
x(100)
// Parses as zoink(++n), actually calling zoink,
//  and returning undefined.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.