JavaScript Interview Questions

23 Questions
JavaScript

JavaScript

Web DevelopmentFrontendBackend

Question 7

What are the different data types in JavaScript?

Answer:

JavaScript has six primitive data types: string, number, boolean, null, undefined, and symbol. Additionally, it has one complex data type: object, which includes arrays and functions. Understanding these data types is fundamental to working with JavaScript, as it affects how variables are declared, compared, and manipulated.

Here are examples of each data type:

// String
let name = 'John';

// Number
let age = 30;

// Boolean
let isMarried = true;

// Null
let car = null;

// Undefined
let address;

// Symbol
let sym = Symbol('symbol');

// Object
let person = {
    name: 'John',
    age: 30,
    isMarried: true
};

// Array (a type of object)
let colors = ['red', 'green', 'blue'];

// Function (a type of object)
function greet() {
    console.log('Hello');
}

In this example, we demonstrate the declaration of each data type, showing the versatility and range of values that can be managed within JavaScript.

Recent job openings