1. JavaScript Basics
1. What is JavaScript?
o JavaScript is a high-level, interpreted programming language used to
create dynamic web pages. It enables interactivity, such as form
validation, animations, and API calls.
2. How is JavaScript different from Java?
o Java is a compiled, statically-typed language, while JavaScript is
interpreted and dynamically-typed.
o Java is mainly used for backend applications, whereas JavaScript is
mostly used for web development.
3. What are the different ways to declare a variable in JavaScript?
o var (function-scoped)
o let (block-scoped)
o const (block-scoped and immutable)
4. What is the difference between == and === in JavaScript?
o == checks for value equality with type coercion.
o === checks for both value and type equality.
5. What are the different data types in JavaScript?
o Primitive Types: String, Number, Boolean, Undefined, Null, Symbol,
BigInt.
o Reference Types: Objects, Arrays, Functions.
2. Functions & Scope
6. What is a function in JavaScript?
o A function is a block of reusable code that performs a specific task.
7. What are the different types of functions in JavaScript?
o Named Functions: function greet() {}
o Anonymous Functions: const greet = function() {}
o Arrow Functions: const greet = () => {}
, 8. What is the difference between function declaration and function
expression?
o Function Declaration: Defined using function keyword and can be
hoisted.
o Function Expression: Stored in a variable and cannot be hoisted.
9. What is closure in JavaScript?
o A function that remembers variables from its outer scope even after
the outer function has finished executing.
10.What is the difference between global and local scope?
Global Scope: Variables declared outside any function are accessible
everywhere.
Local Scope: Variables declared inside a function are accessible only within
that function.
3. Objects & Prototypes
11.What is an object in JavaScript?
o An object is a collection of key-value pairs used to store and manage
data.
12.How do you create an object in JavaScript?
o Using object literals: const obj = { key: 'value' };
o Using the new Object() syntax: const obj = new Object();
13.What is a prototype in JavaScript?
o A prototype is an object from which other objects inherit properties
and methods.
14.What is the difference between prototypal and classical inheritance?
o Classical Inheritance (like Java) uses classes to create objects.
o Prototypal Inheritance (JavaScript) allows objects to inherit directly
from other objects.
15.How do you add a method to a prototype?
o MyObject.prototype.myMethod = function() { return 'Hello'; }
, 4. Asynchronous JavaScript
16.What is asynchronous programming in JavaScript?
o A method of execution that allows the program to continue running
while waiting for operations to complete.
17.What is the difference between synchronous and asynchronous code?
o Synchronous: Executes line by line, waiting for each task to
complete.
o Asynchronous: Allows multiple tasks to run simultaneously.
18.What are callbacks in JavaScript?
o A function passed as an argument to another function that is
executed later.
19.What are Promises in JavaScript?
o Objects that represent the eventual completion (or failure) of an
asynchronous operation.
20.What is async and await in JavaScript?
o async makes a function return a promise.
o await waits for a promise to resolve before continuing execution.
5. ES6+ Features
21.What are some new features introduced in ES6?
o let and const
o Arrow Functions
o Template Literals
o Destructuring Assignment
o Default Parameters
22.What is the spread operator (...) in JavaScript?
o Used to spread elements of an array or object into a new array or
object.
23.What is destructuring in JavaScript?
o A syntax that allows you to unpack values from arrays or properties
from objects into distinct variables.
24.What are template literals in JavaScript?