Back to Basics: JavaScript Operators, Conditionals & Functions

It is essential to have a firm grasp of the fundamentals before delving into creating programs with JavaScript. In this article, we will go over some of the most important basic concepts of JavaScript that will allow you to start writing your own programs: operators, conditional statements, and functions.

JavaScript Operators

JavaScript operators are symbols that are used to perform different operations on data. There are several types of operators in JavaScript, and in this lesson we’ll learn about the most common ones: assignment operators, arithmetic operators, comparison operators, and logical operators.

Assignment Operators

Assignment operators, in their most basic form, apply data to a variable. In this example, I’ll assign the string “Europe” to the variable continent.

var continent = "Europe";  

Assignment is represented by the equals sign (=). Although there are other types of assignment operators, which you can view here, this is by far the most common.

You can test all the examples throughout this article by using the console.log() function, or by using the Console.

Arithmetic Operators

JavaScript, like all programming languages, has the built-in ability to do math, just like a calculator. Arithmetic operatorsperform mathematic calculations on numbers, or variables that represent numbers. You already know the most common of these — addition, subtraction, multiplication, and division.


The addition operator, represented by a plus sign (+), will add two values and return the sum.

var x = 2 + 2; // x returns 4  


The subtraction operator, represented by a minus sign (-), will subtract two values and return the difference.

var x = 10 - 7; // x returns 3  


The multiplication operator, represented by an asterisk (*), will multiply two values and return the product.

var x = 4 * 5; // x returns 20  


The division operator, represented by a forward slash (/), will divide two values and return the quotient.

var x = 20 / 2; // x returns 10  


Slightly less familiar is the modulus operator, which returns the remainder after division, and is represented by the percentage sign (%).

Read Full Article

Leave a Reply

Your email address will not be published.