JavaScript: Step 1 – Data Types and Variables

In programming, data types are used to define the type of data that a variable can hold. A variable is a named container that stores a value.

In JavaScript, there are several data types, including:

Data TypeDescriptionExample
stringA sequence of characters“Hello World”
numberA numerical value42
booleanA true/false valuetrue
nullA variable with no valuenull
undefinedA variable that has not been assigned a valueundefined
objectA complex data type that can hold multiple values{ name: “John”, age: 30 }
symbolA unique value that cannot be changedlet id = Symbol()

Variables can be declared using the var, let, or const keywords. var and let can be used to declare variables that can be reassigned, while const is used to declare constants that cannot be reassigned.

Example program:

// Declare a string variable
let message = "Hello World";

// Declare a number variable
let age = 42;

// Declare a boolean variable
let isStudent = true;

// Declare a null variable
let x = null;

// Declare an undefined variable
let y;

// Declare an object variable
let person = { name: "John", age: 30 };

// Declare a symbol variable
let id = Symbol();



Hello World
{ name: 'John', age: 30 }

To run this program in Visual Studio Code IDE after installing node.js:

  1. Open Visual Studio Code
  2. Create a new file and save it with a .js extension (e.g. data_types.js)
  3. Copy and paste the code above into the file
  4. Open the terminal in Visual Studio Code (View > Terminal)
  5. Type node data_types.js in the terminal and press Enter
  6. The output should be displayed in the terminal window.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.