0% found this document useful (0 votes)
4 views4 pages

JavaScript Test

The document contains a series of JavaScript code snippets and questions related to their outputs and behaviors, including concepts like event handling, type checking, and variable scope. It also discusses event delegation, keyboard events, and the implications of using preventDefault() in different scenarios. Additionally, it addresses the differences between various event types and their practical applications in web development.

Uploaded by

mohitrachhoti
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views4 pages

JavaScript Test

The document contains a series of JavaScript code snippets and questions related to their outputs and behaviors, including concepts like event handling, type checking, and variable scope. It also discusses event delegation, keyboard events, and the implications of using preventDefault() in different scenarios. Additionally, it addresses the differences between various event types and their practical applications in web development.

Uploaded by

mohitrachhoti
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

1. What is the output?

[Link](typeof null);

2. What is the output?

[Link](NaN === NaN);

3. What is the output?

[Link]([] == false);

4. What is the output?

[Link]("5" - 2 + "3");

5. What is the output?

[Link](1 + "2" + 3 - 1);

6. What will be printed?

var a = 10;

(function () {

[Link](a);

var a = 20;

})();

7. What is the output?

[Link](typeof typeof 100);

8. What is the output?

var arr = [];

arr[10] = 50;

[Link]([Link]);
9. What is the output?

var x = [1, 2, 3];

var y = x;

[Link](4);

[Link](x);

10. What is the output?

[Link](0 == false && "" == false);

11. What happens here?

foo();

var foo = function () {

[Link]("Hello");

};

12. What is the output?

[Link]([1, 2] + [3, 4]);

13. What is the output?

[Link](true + false + "1");

14. What is the output?

[Link]([Link]());

15. What is the output?

[Link](typeof NaN);
Click Event Logic

What will happen when the button is clicked twice?

<button id="btn">Click</button>

<script>

var count = 0;

[Link]("btn").addEventListener("click", function () {

count++;

[Link](count);

});

</script>

Write the output after 2 clicks.

click vs dblclick

Can both click and dblclick events fire on the same element?
Explain with reason (no code required).

change Event Behavior

When does the change event fire for:

• <input type="text">

• <select>

Explain the difference clearly.

Event Bubbling (Conceptual)

Given this structure:

<div id="parent">

<button id="child">Click</button>

</div>

If both parent and child have click events,


which event runs first and why?

preventDefault() Scenario
What happens if preventDefault() is used on:

• a link (<a>)

• a form submit

Explain real-life use cases.

Keyboard Event Logic

What is the difference between:

• keydown

• keyup

• input

Which one is best for form validation and why?

Event Delegation

Why is event delegation preferred when handling events for dynamic elements (like list items
added later)?

Explain without code.

Window Events

Name any three window events and give one real use case for each.

Scroll Event Performance

Why should heavy logic NOT be written directly inside the scroll event?

What problem does it cause?

Focus & Blur Events

What is the difference between:

• focus

• blur

Give one real-world example for each.

You might also like