COMPUTER SCIENCE CAFÉ
  • WORKBOOKS
  • BLOCKY GAMES
  • GCSE
    • CAMBRIDGE GCSE
  • IB
  • A LEVEL
  • LEARN TO CODE
  • ROBOTICS ENGINEERING
  • MORE
    • CLASS PROJECTS
    • Classroom Discussions
    • Useful Links
    • SUBSCRIBE
    • ABOUT US
    • CONTACT US
    • PRIVACY POLICY
  • WORKBOOKS
  • BLOCKY GAMES
  • GCSE
    • CAMBRIDGE GCSE
  • IB
  • A LEVEL
  • LEARN TO CODE
  • ROBOTICS ENGINEERING
  • MORE
    • CLASS PROJECTS
    • Classroom Discussions
    • Useful Links
    • SUBSCRIBE
    • ABOUT US
    • CONTACT US
    • PRIVACY POLICY
JAVASCRIPT | OPERATORS
ON THIS PAGE
SECTION 1 | ARITHMETIC OPERATORS
SECTION 2 | COMPARISION OPERATORS
SECTION 3 | ASSIGNING OPERATORS
SECTION 4 | LOGIC OPERATORS
​SECTION 5 | EXAMPLES

ALSO IN THIS TOPIC
GETTING STARTED

 ​VARIABLES & USER INPUT
YOU ARE HERE | OPERATORS
CONDITIONALS (IF STATEMENTS)
​ITERATION (LOOPS)
ARRAYS (LISTS)
FUNCTIONS

FURTHER JAVASCRIPT

Picture
WHAT ARE OPERATORS
Operators are used to do mathematical operations, comparison operations, logic operators and assigning value operations for example if you do: num1 = 10 then you have used the = (equals) operator to assign the value of 10 to the variable num1. There are many different operators as can be seen in the four categories below.
STEP 1 | ARITHMETIC OPERATORS
As the name suggests, arithmetic operators are used to perform calculations. Popular arithmetic operators can be seen in the table below.
Picture
JavaScript also have the Increment and Decrement operators
  • Increment: ​++
  • Decrement: --
STEP 2 | COMPARISON OPERATORS
As the name suggests, comparison operators are used compare values. Popular comparison operators can be seen in the table below.
Picture
REMEMBER:
  • One equals sign, means make it equal to
  • Two equal signs mean is it equal to ?

STEP 3 | ASSIGNING OPERATORS
As the name suggests, assigning operators are used assign values to variables. Popular assigning operators can be seen in the table below.
Picture
STEP 4 | LOGIC OPERATORS
As the name suggests, logic operators are used like logic gate, they are frequently used in IF statements and can be used as stand alone operators. Popular logic operators can be seen in the table below.
Picture
In JavaScript you can use the following to represent AND / NOT / OR
  • Logical AND - &&
  • Logical OR - ||
  • Logical NOT - !
SECTION 5 | OPERATOR EXAMPLES
Operators are fundamental building blocks in programming. They allow us to manipulate data, make decisions, and structure our code in meaningful ways. As you continue your coding journey, you'll encounter and use these operators frequently, making them essential tools in your developer toolkit. Here are some examples of operators in use, copy and try them out in VSC and experiment, for example change the age value to less than 18 and see what happens.
Code Editor

    
Picture
OPERATORS
QUESTION
1:Which operator could you use to determine if a given value is odd or even, and how could you use it? 

TASK 
Create a program to:
1: Ask the user to enter a number
2: Write a line of code to calculate the DIV of the number given and save the answer in a new variable
3: Output to the user the answer in a user friendly string concatenated with the numeric answer.

TRY
Have a go at using some of the other operators to see how they work, don't be afraid to experiment.
Picture
NAVIGATION
GETTING STARTED
​VARIABLES & USER INPUT
 OPERATORS
CONDITIONALS (IF STATEMENTS)
 ​ITERATION (LOOPS)
ARRAYS (LISTS)
FUNCTIONS

FURTHER JAVASCRIPT
Picture
SUGGESTIONS
We would love to hear from you
SUBSCRIBE 
To enjoy more benefits
We hope you find this site useful. If you notice any errors or would like to contribute material then please contact us.