JavaScript Operators Tutorial

INTERACTIVE CORNER

use this simple JavaScript arithmetic calculator and an operator for results
[INPUT X] [OPERATOR +-*/%] [INPUT Y]


result

JavaScript employs two types of operators to perform different functions. These are known as arithmetic operators and assignment operators. The arithmetic operator is used to perform arithmetic between variables and/or values. The assignment operator is used to assign values to JavaScript variables. For a more detailed explanation on JavaScript Operators visit W3C Schools.

This JavaScript tutorial aims to explain the basic JavaScript operators via a demonstration.

The + Operator used on Values

This script will use = to assign arithmetic values to a variable and use the + operator to add them up.

var x=12,y=27;
var z=(x+y);

 

The + Operator used on Strings

The + operator can also be used to add string variables or text values together.

var xStr="<br />This is ";
var yStr="fun!";
var zStr=(xStr+yStr);

NOTE: If you add a number and a string, the result will always be a string.