TGViewer
Web Development - HTML, CSS & JavaScript Web Development - HTML, CSS & JavaScript @javascript_courses ยท 55.7K subscribers
Post #3424 2.43K
๐Ÿš€ JavaScript Interview Questions with Answers โ€” Part 8

71. What are try/catch/finally? 
These are used for error handling in JavaScript.

Block 
try 
โ€ข Purpose: Code that may cause error

catch 
โ€ข Purpose: Handles the error

finally 
โ€ข Purpose: Always executes

Example: 

try {
    console.log(a);
} catch(error) {
    console.log("Error occurred");
} finally {
    console.log("Execution completed");
}


Output: 

Error occurred
Execution completed


Important: 
finally runs whether an error occurs or not.

72. What is the Error object? 
The Error object contains information about runtime errors.

Example: 

try {
    throw new Error("Something went wrong");
} catch(error) {
    console.log(error.message);
}


Common Error Properties: 

name 
โ€ข Description: Error type

message 
โ€ข Description: Error message

stack 
โ€ข Description: Stack trace

Built-in Error Types: 
โ€ข ReferenceError
โ€ข TypeError
โ€ข SyntaxError
โ€ข RangeError

73. How do you create custom errors? 
Using classes or extending Error.

Example: 

class ValidationError extends Error {
    constructor(message) {
        super(message);
        this.name = "ValidationError";
    }
}

throw new ValidationError("Invalid input");


Benefits: 
โ€ข Better debugging
โ€ข More meaningful error handling

74. What are console.log, console.table, console.group? 
These are debugging methods available in browser DevTools.

console.log() 
Prints normal output. 

console.log("Hello");


console.table() 
Displays data in table format. 

console.table([
    {name: "Deepak", age: 25},
    {name: "John", age: 30}
]);


console.group() 
Groups related logs. 

console.group("User Info");
console.log("Name: Deepak");
console.log("Age: 25");
console.groupEnd();


Benefit: 
Cleaner debugging in large applications.

75. How do you use breakpoints and the debugger? 
Breakpoints pause code execution for debugging.

Using debugger: 

function test() {
    let x = 10;
    debugger;
    console.log(x);
}
test();


How It Works: 
โ€ข Browser pauses at debugger
โ€ข Inspect variables and execution flow

Browser DevTools Features: 
โ€ข Step through code
โ€ข Watch variables
โ€ข Inspect call stack
โ€ข Monitor network requests

Interview Tip: 
Very important skill for frontend developers.

76. What is performance profiling in DevTools? 
Performance profiling helps identify slow operations and bottlenecks.

Browser DevTools Can Measure: 
โ€ข Rendering performance
โ€ข JavaScript execution time
โ€ข Memory usage
โ€ข FPS drops

Common Tabs: 
โ€ข Performance
โ€ข Memory
โ€ข Network

Why It Matters: 
Helps optimize web applications and improve user experience.

77. How do you avoid blocking the main thread? 
Heavy tasks can freeze the UI because JavaScript is single-threaded.

Solutions: 
1. Use asynchronous operations
2. Break heavy tasks into chunks
3. Use Web Workers
4. Use setTimeout()
5. Optimize loops

Example: 

setTimeout(() => {
    heavyTask();
}, 0);


Why? 
Allows browser to handle UI updates before running heavy code.

78. What is debouncing vs throttling? 
Both optimize frequent function calls.

Debouncing 
Runs function only after user stops triggering event.

Example Use Cases: 
โ€ข Search input
โ€ข Resize events

function debounce(fn, delay) {
    let timer;
    return function() {
        clearTimeout(timer);
        timer = setTimeout(() => {
            fn();
        }, delay);
    };
}


Throttling 
Limits function execution to fixed intervals.

Example Use Cases: 
โ€ข Scroll events
โ€ข Mouse movement

function throttle(fn, delay) {
    let lastCall = 0;
    return function() {
        let now = Date.now();
        if (now - lastCall >= delay) {
            lastCall = now;
            fn();
        }
    };
}


Difference: 

Debounce 
โ€ข Waits after last event
โ€ข Reduces extra calls

Throttle 
โ€ข Executes at intervals
โ€ข Limits execution frequency
  • โค 6
More from @javascript_courses
  1. Oct 8, 2026๐ŸŽ“ ๐— ๐—ถ๐—ฐ๐—ฟ๐—ผ๐˜€๐—ผ๐—ณ๐˜ ๐—™๐—ฅ๐—˜๐—˜ ๐—–๐—ผ๐˜‚๐—ฟ๐˜€๐—ฒ๐˜€ ๐˜„๐—ถ๐˜๐—ต ๐—–๐—ฒ๐—ฟ๐˜๐—ถ๐—ณ๐—ถ๐—ฐ๐—ฎ๐˜๐—ฒ๐˜€! ๐Ÿš€๐Ÿ”ฅ Upgrโ€ฆ
  2. Oct 7, 2026๐Ÿš€๐—ฃ๐—ฎ๐˜† ๐—”๐—ณ๐˜๐—ฒ๐—ฟ ๐—ฃ๐—น๐—ฎ๐—ฐ๐—ฒ๐—บ๐—ฒ๐—ป๐˜ ๐—ง๐—ฟ๐—ฎ๐—ถ๐—ป๐—ถ๐—ป๐—ด | ๐—•๐—ฒ๐—ฐ๐—ผ๐—บ๐—ฒ ๐—ฎ ๐—™๐˜‚๐—น๐—น๐˜€๐˜๐—ฎ๐—ฐโ€ฆ
  3. Oct 7, 2026๐— ๐—ฎ๐˜€๐˜๐—ฒ๐—ฟ ๐—ฃ๐—ผ๐˜„๐—ฒ๐—ฟ ๐—•๐—œ ๐—ณ๐—ผ๐—ฟ ๐—™๐—ฅ๐—˜๐—˜! ๐Ÿ”ฅ Learn Power BI through these FREE learninโ€ฆ
  4. Oct 4, 2026DSA Handwritten Notes
  5. Sep 28, 2026To learn web design and development from basic to advanced levels, you can follow these stโ€ฆ
  6. Sep 27, 202610 Websites Every Developer & AI Enthusiast Should Bookmark โœ… roadmap.sh โ€“ Step-by-step leโ€ฆ
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook โ†’Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 โ†’