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.
- 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
- Free certificates of completion
- Focused on data science skills
- Flexible learning timetable
- Simplistic design (no unnecessary information)
- High-quality courses (even the free ones)
- Variety of features
- Nanodegree programs
- Suitable for enterprises
- Paid Certificates of completion
- A wide range of learning programs
- University-level courses
- Easy to navigate
- Verified certificates
- Free learning track available
- University-level courses
- Suitable for enterprises
- Verified 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:
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. |