Important Javascript Questions And Answers For Beginners
by Digyfindy
Tags:
1. Purpose of JavaScript
JavaScript makes web pages come alive. HTML builds the structure, CSS makes it look nice, and JavaScript adds brainpower—like buttons that respond when you click them, dropdowns, or games running in the browser.
2. Key Features
-
Lightweight and easy to learn
-
Runs directly in the browser
-
Supports both object-oriented and functional programming
-
Asynchronous (doesn’t always wait in line, which is why you can fetch data without freezing the page)
3. Data Types
Two categories:
-
Primitive: string, number, boolean, null, undefined, symbol, bigint
-
Non-primitive: objects, arrays, functions
ð Example:
4. Closure
A closure happens when a function “remembers” the variables from its outer scope, even after that scope has gone away.
5. == vs === Operators
-
==checks only values (loose equality). -
===checks both value and type (strict equality).
6. Difference Between Null and Undefined
-
undefined → a variable declared but not assigned.
-
null → an intentional empty value.
7. Event Delegation
Instead of attaching event listeners to every element, you attach one to the parent and handle children via event.target. Saves memory and keeps code clean.
8. Callback
A callback is a function passed into another function to run later.
9. Hoisting
JavaScript “hoists” variable and function declarations to the top.
10. Let, Const, and Var
-
var: function-scoped, can be redeclared. -
let: block-scoped, can be updated but not redeclared. -
const: block-scoped, cannot be reassigned.
11. Event Bubbling and Capturing
Events travel:
-
Bubbling → child → parent
-
Capturing → parent → child
12. Event Loop
JavaScript is single-threaded. The event loop manages the stack (synchronous tasks) and queue (asynchronous tasks) so nothing gets stuck.
13. this Keyword
this refers to the object that’s calling the function.
-
In a method → object itself
-
In global scope →
window(in browsers)
14. Function Declaration
15. Function Expression
16. Prototypal Inheritance
Objects in JavaScript can inherit properties from other objects using prototypes.
17. Promise
Used for handling async tasks.
18. "use strict"
Makes JavaScript more strict about errors. Prevents silent mistakes.
19. Map Object
Stores key-value pairs. Keys can be objects, not just strings.
20. Set Object
Stores unique values. No duplicates allowed.
21. Async / Await
Syntactic sugar for promises. Looks synchronous, but isn’t.
22. Higher-Order Functions
Functions that take other functions as arguments or return them. Example: map(), filter().
23. Currying
Breaking a function with multiple arguments into multiple functions with one argument each.
24. Memoization
Caching function results so repeated calls are faster.
25. Array Methods
-
map()→ transform each element -
filter()→ keep only matching elements -
reduce()→ combine values -
forEach()→ loop through -
find()→ first matching element -
some()→ checks if at least one matches -
every()→ checks if all match -
sort()→ sorts values