🚨 Time is Running Out: Reserve Your Spot in the Lucky Draw & Claim Rewards! START NOW

Code has been added to clipboard!

Statements

Reading time 3 min
Published Aug 9, 2017
Updated Oct 2, 2019

JavaScript Statements: Main Tips

  • JavaScript statements are specific instructions used to inform the computer of the assigned task.
  • Each statement sends a unique instruction.
  • Each statement should end with a semicolon. It is not required but it is a good practice to keep your code organized.
DataCamp
Pros
  • Easy to use with a learn-by-doing approach
  • Offers quality content
  • Gamified in-browser coding experience
  • The price matches the quality
  • Suitable for learners ranging from beginner to advanced
Main Features
  • Free certificates of completion
  • Focused on data science skills
  • Flexible learning timetable
Udacity
Pros
  • Simplistic design (no unnecessary information)
  • High-quality courses (even the free ones)
  • Variety of features
Main Features
  • Nanodegree programs
  • Suitable for enterprises
  • Paid Certificates of completion
Udemy
Pros
  • Easy to navigate
  • No technical issues
  • Seems to care about its users
Main Features
  • Huge variety of courses
  • 30-day refund policy
  • Free certificates of completion

What Statements Are

Basically, any JavaScript code consists of a variety of statements that guide a program or a website, and control their functionality. Writing JavaScript code without such functions is impossible: statements specify the actions the script will perform. Without them, you would have a bunch of elements with nothing to do.

Many programming languages require developers to end their statements with semicolons, but JavaScript gives them a choice. Anyway, even though JavaScript statements do not require the usage of semicolons, it can help you manage your code better.

The code example below shows one of the most simple JavaScript statements. It will write a message on the screen:

Example
document.write("Hello there");

It's crucial that you don't mistake statements for expressions. The discussion of expression vs statement usually mentions that statements are lines of code that determine the sequence of actions, while any piece of code, evaluating to a value, can be identified as an expression.

List of Identifiers

When writing your code, you should keep in mind that JavaScript statement identifiers cannot be set as variable or function names. JavaScript statements begin with identifiers and end with other components such as arguments.

In other words, identifiers specify the function to be performed. They belong to the group of reserved words in JavaScript.

All JavaScript statement identifiers can be found in the table below:

Keyword Description
break Ends a loop command.
continue Ends and restarts a loop command.
debugger Stops JavaScript from running and calls the debugging function, if possible.
do ... while Runs and loops a block of code until a condition is no longer true.
for Loops a block of code until a specified condition is no longer true.
for ... in Specifies the code to execute for every element in a specified object.
function Defines a function.
if ... else Checks a specified condition and executes a block of code if it is true.
return Returns a specified value and exits the current function.
switch Sets multiple conditions and blocks of code.
throw Generates an error.
try ... catch Defines an error handling block of code.
var Declares a new variable.
while Loops a block of code while a specified condition is true.