I always assumed that all whitespace (spaces, tabs, newlines) in JavaScript source code was 'equal', i.e. they're all valid to separate language elements such as identifiers, keywords, operators, etc.
However, I noticed a strange difference between newlines versus spaces or tabs. Even inside comments!
This works OK: (line break between function definition and function call, but no semicolon)
var bla = function() { alert('hello') }
bla();
This also works: (semicolon between the closing } character and the bla() function call)
var bla = function() { alert('hello') };bla();
However, this does NOT work: (no difference whether there's just one space or tab, or multiple, or none)
var bla = function() { alert('hello') } bla();
And it gets even stranger.
This doesn't work either: (separated by comment containing space, tab and semicolon)
var bla = function() { alert('hello') } /* ; */ bla();
But this does: (comment containing line break)
var bla = function() { alert('hello') }/*
*/bla();
Live jsfiddle demos:
- line break (OK)
- semicolon (OK)
- space or tab (not OK)
- comment containing space, tab and semicolon (not OK)
- comment containing line break (OK!)
Is this a bug in JavaScript, or am I missing something?