W3C.US

  • Increase font size
  • Default font size
  • Decrease font size
Home Tutorial Javascript Book Blank char and semicolon

Blank char and semicolon

E-mail Print PDF

Some characters in javascript are treated as blank char, including space(0x20), table(0x09), enter(0x0D,0x0A).

Blank char is used to make the code for reading and understanding. If insert a blank char into a token(keyword, variable, number), then the token is seperated to 2 parts, not one token, sometimes it causes an error.

Semicolon is used to end one sentence, like:

a = 1;

b = 2;

 

 

In javascript, the line-ending semicolon  is not necessary. Above code can be written as:

a=1

b=2

But if the line is

a = 1; b = 2;

The first semicolon can not be removed.

 

It is recommended to add semicolon to every sentences ending, and do not cut the break and return sentence to two lines.

For example:

return true;

If you cut it to 2 lines:

return

true;

it only return, but not return a true value.

Last Updated on Monday, 04 May 2009 22:43