Clean β’ Professional
Ques: What are advanced JavaScript concepts?
Ans: Advanced JavaScript concepts go beyond basic syntax and cover topics like Strict Mode, Modules, Closures, Asynchronous programming, and Debugging techniques β all essential for writing efficient, scalable, and secure JavaScript code.
Ques: Why is learning advanced JavaScript important?
Ans: Because modern web apps require:
Ques: Name a few advanced JavaScript topics developers must know.
Ques: What is Strict Mode in JavaScript?
Ans: Strict Mode is a restricted variant of JavaScript introduced in ES5 that helps catch common coding errors and unsafe actions early.
Itβs enabled by adding "use strict"; at the beginning of a script or function.
"use strict";
x = 10; // Error: x is not defined
Ques: How do you enable Strict Mode?
Ans: You can enable it:-
For the entire script:
"use strict";
For a single function:
function test() {
"use strict";
// code here
}
Ques: What are the benefits of using Strict Mode?
with statement)Ques: What happens if you use undeclared variables in Strict Mode?
Ans: It throws a ReferenceError instead of creating a global variable automatically.
"use strict";
x = 5; // ReferenceError
Ques: Can you use Strict Mode in ES modules by default?
Ans: Yes, All ES Modules (import / export) automatically run in Strict Mode.
Ques: What is not allowed in Strict Mode?
010)with statementsQues: Example showing Strict Mode catching silent errors:
"use strict";
delete Object.prototype; // TypeError
Ques: What are JavaScript Modules?
Ans: Modules are independent files that encapsulate code and export or import functionalities.
They help organize JavaScript projects into reusable components.
Ques: Why use Modules?
Ques: How do you export code from a module?
Ans: You can use named or default exports.
// named export
export const name = "JavaScript";
// default export
export default function greet() {
console.log("Hello JS!");
}
Ques: How do you import a module in JavaScript?
import { name } from "./file.js";
import greet from "./file.js";
Ques: Can you rename imports?
Ans: Yes.
import { name as lang } from "./file.js";
Ques: What is the difference between Named Export and Default Export?
| Feature | Named Export | Default Export |
|---|---|---|
| Exported Name | Must match during import | Can use any name |
| Number per file | Many | Only one |
| Syntax | export {} | export default |
Ques: What is the difference between ES Modules and CommonJS?
| Feature | ES Modules | CommonJS |
|---|---|---|
| Used In | Browser, Node.js (new) | Node.js (old) |
| Syntax | import/export | require/module.exports |
| Loading | Static | Dynamic |
Ques: Example of mixing imports and exports:
// utils.js
export const PI = 3.14;
export default function area(r) {
return PI * r * r;
}
// main.js
import area, { PI } from "./utils.js";
console.log(area(5));
Ques: Can modules run without a web server?
Ans: No, You must run modules through a server environment (like http-server) or frameworks (like React, Vite, or Node.js with "type": "module").
Ques: Are modules in JavaScript automatically in Strict Mode?
Ans: Yes, All ES6 modules automatically run in Strict Mode β no need to add "use strict" manually.
Ques: What is debugging?
Ans: Debugging is the process of finding and fixing errors (bugs) in your JavaScript code using tools like the browser console or debugger keyword.
Ques: What are common debugging tools in JavaScript?
console.log, console.error, console.table)Ques: What is the use of console.log()?
Ans: It prints information to the browser console β commonly used for quick debugging.
console.log("Value of x:", x);
Ques: What are some other useful console methods?
| Method | Description |
|---|---|
console.warn() | Displays a warning message |
console.error() | Displays an error message |
console.table() | Displays tabular data |
console.group() | Creates grouped logs |
console.time() / console.timeEnd() | Measures performance |
Ques: What is the debugger keyword used for?
Ans: When the browser encounters debugger;, it pauses code execution and allows inspection of variables and call stack.
function test(num) {
debugger; // pause here
return num * 2;
}
test(10);
Ques: How do you add breakpoints in JavaScript?
Ans: Open DevTools β Sources tab β Click line number β Adds a breakpoint.
When the code runs, it pauses at that line.
Ques: What are watch expressions in debugging?
Ans: They let you monitor specific variables or expressions while the code runs, helping trace their changing values.
Ques: What is step-by-step debugging?
Ans: You can step through code line by line using:
Ques: How can you debug asynchronous code (Promises / async-await)?
console.log inside .then() or await sectionsQues: What are best practices for debugging JS efficiently?
console.log in productionconsole.group)