Conditional Statements in JavaScript

Taimoor Sattar

Conditional Statements execute certain operations based on logic. In Javascript, we can execute the conditional statements in three (3) ways as below:

  • ternary operator
  • if / else logic
  • switch statement

let suppose, we have a variable in Javascript as below:

let isMember = true;

We can perform condition statements in javascript as below:

ternary operator:

// ternary operator
let price= isMember ? '$2.00' : '$10.00'

if / else logic:

// if / else logic
  price = '$2.00'
  price = '$10.00'

switch statement:

// switch statement
switch(isMember) {
  case true:
    price = '$2.00';
  case y:
    price = '$10.00'
    price = '$2.00';

About the Author


Taimoor Sattar
I'm a full-stack developer and educator. I've always been intrigued by languages used elegantly and efficiently, regardless of whether they are interpreted by humans or computers.