JavaScript Syntax


JavaScript Keywords

JavaScript keywords are some reserved words that can’t be used as identifier and are used to identify actions to be performed e.g., the var keyword tells the browser to declare variables in JavaScript.

Here is the list of JavaScript keywords:

abstract arguments await boolean
break byte case catch
char class const continue
debugger default delete do
double else enum eval
export extends false final
finally float for function
goto if implements import
in instanceof int interface
let long native new
null package private protected
public return short static
super switch synchronized this
throw throws transient true
try typeof var void
volatile while with yield

Whitespace and Line Breaks in JavaScript

JavaScript ignores spaces, tabs, and newline characters that appear in JavaScript programs.

Spaces, tabs, and newlines can be used freely.

This allows you to format and indent the programs in a neat and consistent way that increases readability.

Optional Semicolons in JavaScript

Generally the statements in JavaScript are followed by a semicolon.

However, JavaScript also allows you to omit this semicolon if each of the statements is placed on a separate line.

For example, the following code snippet can be written without semicolons:

But when written in a single line as follows, semicolons must be used

Case Sensitivity

JavaScript is case-sensitive which means that the JavaScript keywords, variables, function names, and any other identifiers must always be typed maintaining a consistent capitalization of letters.

So the identifiers DATE, date and Date will convey different meanings in JavaScript.

Comments in JavaScript

  • Anything written between a // and the end of a line is treated as a comment and is not executed by JavaScript.
  • Any text between the characters /* and */ is treated as a multiple line comment.
  • JavaScript recognizes the HTML comment opening <!–. JavaScript treats this as a single-line comment, just like the // comment.
  • The HTML comment closing sequence –> is not considered as a comment by JavaScript so it must be written as //–>.