1.What is JavaScript, and why is it used?
JavaScript is the programming language of the web.
It can calculate, manipulate and validate data.
It can update and change both HTML and CSS
JavaScript was invented by American programmer Brendan Eich in 1995.
2.What are variables in JavaScript?
Variables are containers for storing data.
3.Difference between var, let, and const
var → old way, function‑scoped, can be redeclared.
let → block‑scoped, can be updated but not redeclared.
const → block‑scoped, cannot be reassigned.
4.Different data types in JavaScript
Primitive: Number, String, Boolean, Null, Undefined, Symbol, BigInt
Non‑Primitive: Object (includes arrays, functions, dates)
5.Difference between primitive and non‑primitive
primitive-Basic, single values (not objects) and They are immutable (cannot be changed directly).
Non-primitive-complex data structures that can hold multiple values and They are mutable (values inside can be changed).
6.What is the difference between null and undefined?
null-An intentional empty value and You set a variable to null when you want to say “this has no value.”
undefined- A variable has been declared but not assigned any value and Happens automatically if you don’t give a variable a value.
7.What are operators in JavaScript? Mention the different types of operators.
Operators are for Mathematical and Logical Computations
Arithmetic(+, -, *, /, %)
Assignment (=, +=, -=)
Comparison(==, ===, !=, >, <)
Logical (&&, ||, !)
Increment/Decrement (++, --)
Ternary (condition ? value1 : value2)
8.What is the difference between == and ===?
== - Compares values but does type conversion if needed
=== - Compares both value and type. No conversion happens.
9.What is the difference between ++i and i++?
++i → pre‑increment (increase first, then use).
i++ → post‑increment (use first, then increase).
10.What is a function in JavaScript, and why do we use functions?
A function is a block of code that performs a task. It avoids repetition and makes code reusable.
Functions are executed when they are called or invoked
Functions are fundamental in all programming languages
11.What is a function declaration?
It is start with function keyword followed by function name and It can be called before they are defined.
12.What is a function expression?
In this functions are store in variable and It cannot be called before they are defined.
13.What is an arrow function?
It is shorter syntax of the function expression
14.What is the difference between a regular function and an arrow function?
Regular Function:
Declared with the function keyword.
Has its own this context (depends on how it’s called).
Can be used as a constructor with new.
Arrow Function:
Shorter syntax using =>.
Does not have its own this (inherits from surrounding scope).
Cannot be used as a constructor.
15.What is a callback function? Give a simple example
A callback function is a function passed as an argument to another function.
The main function executes the callback later, often after finishing some task.
Useful for handling asynchronous tasks (like waiting for data, timers, events).
eg:
function greet(name, callback) {
console.log("Hello " + name);
callback();
}
greet("Saran", () => console.log("Welcome!"));
16.What is an array in JavaScript, and how do you access its elements?
An Array is an object type designed for storing data collections.
How to Access Elements
Use the index number inside square brackets [ ].
Index starts at 0 (first item)
17.What are some commonly used array methods in JavaScript?
push() → add at end
pop() → remove last
shift() → remove first
unshift() → add at start
map(), filter(), reduce() → transform data
forEach() → loop through elements
18.What is an object in JavaScript, and how do you access object properties?
Objects are variables that can store both values and functions
You can access values in two ways:
Dot notation
Bracket notation
19.What is the difference between an array and an object in JavaScript?
Array:
Ordered collection of values.
Index-based: Each item has a numeric index starting from 0.
object:
Collection of key–value pairs.
Key-based: Each property has a name (string key).
an object like a dictionary with named entries.
20.How can you add, update, and delete properties in a JavaScript object?
let person = { name: "Saran" };
person.age = 22; // add
person.name = "Vishwa"; // update
delete person.age; // delete
Top comments (0)