JavaScript Interview Questions

author image Hirely
at 05 Jan, 2025

Question: What is JavaScript?

Answer:

JavaScript is a high-level, interpreted programming language primarily used for creating dynamic and interactive content on websites. It is one of the core technologies of web development, alongside HTML and CSS. JavaScript enables features such as interactive forms, animations, real-time updates, and more on the web. It is supported by all modern web browsers and can be used both on the client-side (in the browser) and server-side (with environments like Node.js).

Key Characteristics of JavaScript:

  • Dynamic : JavaScript code can change after a page is loaded, allowing for real-time updates without needing to reload the page.

  • Event-driven : It can respond to user interactions like clicks, form submissions, or keyboard input.

  • Versatile : JavaScript is used in both frontend (browser) and backend (server) development.

  • Object-oriented : JavaScript supports object-oriented programming concepts like inheritance, encapsulation, and polymorphism.

  • Asynchronous : JavaScript uses mechanisms like callbacks, promises, and async/await to handle operations that take time, such as fetching data from a server.

  • Interpreted : It is interpreted by the browser, meaning you don’t need to compile your code before running it. JavaScript is often used with other technologies like React , Vue , or Angular for building user interfaces and Node.js for backend development. It also works in conjunction with other languages and APIs (Application Programming Interfaces) to create comprehensive web applications.

Question: What are the different data types in JavaScript?

Answer:

In JavaScript, there are seven basic data types, which are categorized into primitive and non-primitive (also known as reference ) types.Primitive Data Types : Primitive data types are immutable (their value cannot be changed once they are assigned) and are compared by their value.

  1. String :
  • Represents a sequence of characters enclosed in single quotes ('), double quotes ("), or backticks (```).

  • Example: 'Hello', "World", Hello World

  1. Number :
  • Represents both integer and floating-point numbers.

  • Example: 10, 3.14, -5

  1. BigInt :
  • Used to represent very large integers that exceed the limit of the Number type.

  • Example: 123456789012345678901234567890n

  1. Boolean :
  • Represents one of two values: true or false.

  • Example: true, false

  1. Undefined :
  • Indicates that a variable has been declared but has not yet been assigned a value.

  • Example: let x; // undefined

  1. Null :
  • Represents an intentional absence of any object value or “no value”.

  • Example: let y = null;

  1. Symbol (introduced in ECMAScript 6):
  • Represents a unique and immutable value, often used for object property keys to avoid conflicts.

  • Example: const sym = Symbol('description'); Non-Primitive (Reference) Data Type :

  1. Object :
  • Represents collections of properties, where each property is a key-value pair. Objects can store a variety of values, including arrays, functions, or other objects.

  • Example:

let person = {
  name: 'Alice',
  age: 30,
  isEmployee: true
};
  • Arrays and functions are also considered objects in JavaScript.

Summary:

  • Primitive Types : String, Number, BigInt, Boolean, Undefined, Null, Symbol

  • Reference Types : Object (includes arrays, functions, etc.)

The distinction between primitive and reference types is important because while primitive values are passed by value, reference types are passed by reference, meaning changes to an object affect all references to it.

Read More

If you can’t get enough from this article, Aihirely has plenty more related information, such as JavaScript interview questions, JavaScript interview experiences, and details about various JavaScript job positions. Click here to check it out.

Related Posts

Trace Job opportunities

Hirely, your exclusive interview companion, empowers your competence and facilitates your interviews.

Get Started Now