The Ultimate Guide to Writing JavaScript Statements: Tips for Beginners

When we write code to execute, that is called a programming statement. In this article, we will see how to construct or write JavaScript programming statements.

A JavaScript statement contains: Values, Operators, Expressions, Keywords, and Comments.

Value:

A value is simply what we assign to a variable. For example, someone’s name = “John”, and he got marks = 100 in the math exam, so these are values.

Operators:

These are symbols that perform some actions. Some of the most common examples of operators are:

  • Assignment operator (=): assigns a value to a variable.
  • Addition operator (+): adds multiple variables or values together.
  • Subtraction operator (-): subtracts one value from another.
  • Multiplication operator (*): multiplies multiple variables or values.

There are many other operators like these.

Expression:
An expression is a code unit that gives us a value. Expressions include operators. For example: y = 5;
This unit is an expression. Also, x = 4 + 9 is another example of an expression.

Keywords:
Every programming language consists of some reserved keywords, which have specific meanings for that programming language. JavaScript has many keywords reserved for performing specific actions.
For example: if, const, let, var, function, return, etc.

Comments:
When we write a program, we often need to explain something for ourselves or for someone who will later see our code. Or maybe we want to test a part of the code without running a specific code block. In such cases, we use comments in our code.
A comment tells the program not to run that part of the code, but it still remains in the source. Comments can be for single lines or multiple lines. When we want to comment out just a single line of code, we use //. For multi-line comments, we use /* ... */.

Semicolons:
Each line of JavaScript code is separated using a semicolon (;). When we place the ;, it indicates that the line is finished.

Example:
const name = "Mary";

Leave a Comment