• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 2. Details of the Language > Things to Know about JavaScript Syntax

Things to Know about JavaScript Syntax

Before getting too deep into the core elements of the language, there are a few things a programmer should know about JavaScript syntax. Understanding these points will get you up and programming in a more timely fashion.

The Semicolon

If you have done any programming in C, C++, or Java, even as simple as a Hello World program, you already know 75% of all there is to know about the JavaScript semicolon (;). Just like C and C++, the semicolon is placed at the end of a piece of code to signify that the code between the semicolon and the beginning of the line should be executed before moving to the next portion of code. If you forget a semicolon at the end of a line in C++, you get compile errors, but JavaScript doesn't complain. Because JavaScript is a loosely typed language, forgetting a semicolon tells JavaScript to assume you intended for one to appear at the end of the line, and it executes your code accordingly. This does not mean you should not use semicolons! It is good programming practice to always include semicolons at the end of a line of code except when dealing with statements like for, while, and if.


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint