Variables, Data Types, and Operators in JavaScript

In the previous article, we provided an overview of JavaScript and its key features. In this article, we will cover the basics of JavaScript, including variables, data types, and operators.


Variables are used to store data in a program. In JavaScript, variables are declared using the var keyword, followed by the variable name, and then the value that is assigned to the variable. For example:

var x = 5;

In this example, we are declaring a variable called "x" and assigning it a value of 5.

Data Types

JavaScript supports several data types, including numbers, strings, booleans, objects, and arrays.

  • Numbers:
    Numbers are used to represent numeric values. For example: 3, 3.14, -10, etc.
    Strings: Strings are used to represent text. For example: "Hello, world!", "John Doe", etc.
    Booleans: Booleans are used to represent true/false values. For example: true, false.
    Objects: Objects are used to represent complex data structures. For example:
var person = {name: "John", age: 30, city: "New York"};
  • Arrays:
    Arrays are used to represent a list of values. For example:
var fruits = ["apple", "banana", "orange"];


JavaScript supports several operators, including arithmetic operators, comparison operators, and logical operators.

  • Arithmetic operators:
    Arithmetic operators are used to perform arithmetic operations on numbers. For example: + (addition), - (subtraction), * (multiplication), / (division), % (modulus).
var x = 5;
var y = 2;
var z = x + y; // z = 7
  • Comparison operators:
    Comparison operators are used to compare two values and return a boolean value. For example: == (equal to), != (not equal to), > (greater than), < (less than), >= (greater than or equal to), <= (less than or equal to).
var x = 5;
var y = 2;
var z = x > y; // z = true
  • Logical operators:
    Logical operators are used to combine two or more conditions and return a boolean value. For example: && (logical AND), || (logical OR), ! (logical NOT).
var x = 5;
var y = 2;
var z = (x > y) && (x < 10); // z = true

In summary, variables, data types, and operators are fundamental concepts in JavaScript that are essential for any web developer to understand. In the next article, we will cover control structures in JavaScript, including if/else statements and loops.

*Other Reading
Values and variables

You've successfully subscribed to Leewardslope
Great! Next, complete checkout to get full access to all premium content.
Error! Could not sign up. invalid link.
Welcome back! You've successfully signed in.
Error! Could not sign in. Please try again.
Success! Your account is fully activated, you now have access to all content.
Error! Stripe checkout failed.
Success! Your billing info is updated.
Error! Billing info update failed.