๐ Web Development Interview Questions with Answers โ Part 3: JavaScript
๐ง 46. What is JavaScript?
JavaScript is a programming language used to make web pages interactive.
It is used for:
โข Form validation
โข Dynamic content
โข API calls
โข Animations
โข Interactive UI
Example:
console.log("Hello World");
๐ง 47. Difference Between var, let, and const
var : Function scoped
Can redeclare
Can reassign
let : Block scoped
Cannot redeclare
Can reassign
const : Block scoped
Cannot redeclare
Cannot reassign
Example:
var a = 10;
let b = 20;
const c = 30;
๐ง 48. What are Data Types in JavaScript?
Primitive Data Types:
โข String
โข Number
โข Boolean
โข Null
โข Undefined
โข Symbol
โข BigInt
Non-Primitive:
โข Object
โข Array
โข Function
Example:
let name = "Sanyam";
let age = 26;
let isActive = true;
๐ง 49. Difference Between null and undefined
null : Intentional empty value
undefined : Variable declared but not assigned
Example:
let a = null;
let b;
console.log(b);
๐ง 50. What is Hoisting?
Hoisting means JavaScript moves declarations to the top before execution.
Example:
console.log(a);
var a = 10;
Output:
undefined
๐ง 51. Explain Scope in JavaScript
Scope determines where variables are accessible.
Types:
โข Global Scope
โข Function Scope
โข Block Scope
Example:
{
let age = 26;
}
age cannot be accessed outside block.
๐ง 52. What is Closure?
A closure allows a function to access variables from its outer function even after execution.
Example:
function outer() {
let count = 0;
return function inner() {
count++;
console.log(count);
};
}
const fn = outer();
fn();
๐ง 53. What is Callback Function?
A callback is a function passed into another function.
Example:
function greet(name, callback) {
console.log(name);
callback();
}
greet("Deepak", function() {
console.log("Welcome");
});
๐ง 54. What is Arrow Function?
Arrow functions provide shorter syntax.
Example:
const add = (a, b) => a + b;
Benefits:
โ
Cleaner syntax
โ
Lexical this
๐ง 55. Difference Between == and ===
== : Checks value only
=== : Checks value and type
Example:
5 == "5" // true
5 === "5" // false
๐ง 56. What is Event Bubbling?
Event bubbling means events move from child to parent.
Example:
button.addEventListener("click", () => {
console.log("Button clicked");
});
๐ง 57. What is Event Capturing?
Event capturing is opposite of bubbling.
Event moves: Parent โ Child
Example:
element.addEventListener("click", fn, true);
๐ง 58. What is Event Delegation?
Using parent element to handle child events.
Benefits:
โ
Better performance
โ
Dynamic elements support
Example:
parent.addEventListener("click", (e) => {
console.log(e.target);
});
๐ง 59. What is DOM?
DOM stands for: ๐ Document Object Model
It represents HTML as objects.
Example:
document.getElementById("title");
Post #3756
2.86K
- โค 4