JavaScript Interview Questions Hindi mein

JavaScript Fundamentals: Syntax से Async तक कोर्स के 18 सवाल, हर सवाल के सही जवाब और explanation के साथ। जवाब देखने से पहले ख़ुद सोचें।

मॉड्यूल 2: मूल बातें

1. `typeof null` क्या लौटाता है?

  1. "null"
  2. "undefined"
  3. "object"
  4. "function"
जवाब देखें

जवाब: "object"

यह एक पुरानी JS बग है जिसे बैकवर्ड कम्पेटिबिलिटी के लिए रखा गया है।

पाठ: डेटा टाइप्स

मॉड्यूल 3: कंट्रोल फ्लो

2. किसी ऑब्जेक्ट की अपनी property keys पर चलने के लिए कौन-सा लूप सबसे उपयुक्त है?

  1. for...of
  2. while
  3. do...while
  4. for...in
जवाब देखें

जवाब: for...in

`for...in` खासतौर पर ऑब्जेक्ट की keys गिनने के लिए बना है।

पाठ: लूप्स

मॉड्यूल 5: ऐरे

3. कौन-सा मेथड मूल array जितनी या उससे छोटी नई array लौटाता है?

  1. filter
  2. map
  3. forEach
  4. reduce
जवाब देखें

जवाब: filter

`filter` केवल शर्त पास करने वाले आइटम रखता है, इसलिए नतीजा मूल से लंबा कभी नहीं हो सकता।

पाठ: Iteration: map, filter, reduce, forEach

4. [10, 9, 1].sort() का नतीजा [1, 10, 9] क्यों आता है?

  1. It compares items as strings by default
  2. Sorting is random
  3. Numbers cannot be sorted
  4. It sorts by length
जवाब देखें

जवाब: It compares items as strings by default

Numeric क्रम के लिए (a, b) => a - b दें।

पाठ: Arrays में Search और Sort

मॉड्यूल 6: ऑब्जेक्ट्स

5. `const [a, , b] = [1, 2, 3]` में b का मान क्या होगा?

  1. 2
  2. 3
  3. undefined
  4. 1
जवाब देखें

जवाब: 3

खाली slot इंडेक्स 1 को छोड़ देता है, इसलिए b इंडेक्स 2 उठाता है, जिसमें 3 है।

पाठ: ऐरे और ऑब्जेक्ट Destructuring

मॉड्यूल 8: स्कोप और क्लोज़र

6. काउंटर उदाहरण में, दूसरी बार counter() बुलाने पर 1 नहीं बल्कि 2 क्यों लौटता है?

  1. क्योंकि count हर कॉल पर रीसेट होता है
  2. क्योंकि JS पिछला रिटर्न मान कैश करता है
  3. क्योंकि क्लोज़र कॉल के बीच count को ज़िंदा रखता है
  4. क्योंकि count global variable है
जवाब देखें

जवाब: क्योंकि क्लोज़र कॉल के बीच count को ज़िंदा रखता है

भीतरी फ़ंक्शन `count` को क्लोज़ ओवर करता है, इसलिए यह `counter()` की अलग-अलग कॉल के बीच बना रहता है।

पाठ: क्लोज़र

मॉड्यूल 9: DOM

7. event.preventDefault() क्या करता है?

  1. Event को bubble होने से रोकता है
  2. Event listener को हटा देता है
  3. Page को reload करता है
  4. उस event के लिए ब्राउज़र की डिफ़ॉल्ट क्रिया रोकता है
जवाब देखें

जवाब: उस event के लिए ब्राउज़र की डिफ़ॉल्ट क्रिया रोकता है

जैसे, यह किसी फ़ॉर्म के डिफ़ॉल्ट submit-and-reload व्यवहार को रोकता है — bubbling अलग मामला है जिसे stopPropagation() संभालता है।

पाठ: Event Listener और Bubbling

मॉड्यूल 12: असिंक्रोनस JS

8. Promise चेन में .catch() क्या संभालता है?

  1. चेन में पहले कहीं भी हुई कोई rejection
  2. केवल नेटवर्क त्रुटियाँ
  3. कुछ नहीं — यह केवल logging के लिए है
  4. केवल synchronous errors
जवाब देखें

जवाब: चेन में पहले कहीं भी हुई कोई rejection

पहले किसी भी .then() में हुई rejection बाकी .then() कॉल को छोड़कर सीधे नज़दीकी .catch() पर पहुँच जाती है।

पाठ: प्रॉमिस

मॉड्यूल 16: अन्य विषय

9. setTimeout(fn, 0) fn को तुरंत क्यों नहीं चलाता?

  1. क्योंकि 0ms का मतलब असल में कभी नहीं है
  2. क्योंकि यह fn को मौजूदा call stack खत्म होने के बाद चलाने के लिए queue करता है
  3. क्योंकि setTimeout पूरी तरह सिंक्रोनस है
  4. क्योंकि setTimeout deprecated है
जवाब देखें

जवाब: क्योंकि यह fn को मौजूदा call stack खत्म होने के बाद चलाने के लिए queue करता है

इसका callback 0ms देरी के बावजूद call stack खाली होने का इंतज़ार करता है।

पाठ: JSON, Regex और Event Loop

10. `typeof null` क्या लौटाता है?

  1. "null"
  2. "undefined"
  3. "object"
  4. "number"
जवाब देखें

जवाब: "object"

एक पुरानी विचित्रता: null को object बताया जाता है।

पाठ: JSON, Regex और Event Loop

11. कौन-सा declaration block-scoped है और दोबारा assign नहीं हो सकता?

  1. var
  2. let
  3. function
  4. const
जवाब देखें

जवाब: const

const block-scoped है और binding को स्थिर करता है।

पाठ: JSON, Regex और Event Loop

12. `[1,2,3].map(n => n * 2)` क्या लौटाता है?

  1. [2, 4, 6]
  2. 6
  3. undefined
  4. [1, 2, 3]
जवाब देखें

जवाब: [2, 4, 6]

map नया array लौटाता है।

पाठ: JSON, Regex और Event Loop

13. कौन-सा operator केवल null या undefined पर fallback देता है?

  1. ||
  2. ??
  3. &&
  4. ==
जवाब देखें

जवाब: ??

|| 0 और खाली strings पर भी fallback देता है।

पाठ: JSON, Regex और Event Loop

14. Closure क्या है?

  1. A way to close a browser tab
  2. A loop
  3. A function that remembers variables from where it was created
  4. A module
जवाब देखें

जवाब: A function that remembers variables from where it was created

Closures अपने बनने के scope तक पहुँच बनाए रखते हैं।

पाठ: JSON, Regex और Event Loop

15. event.preventDefault() क्या करता है?

  1. Stops bubbling
  2. Removes the listener
  3. Reloads the page
  4. Stops the browser's default action
जवाब देखें

जवाब: Stops the browser's default action

उदाहरण के लिए यह form submit होने से रोकता है।

पाठ: JSON, Regex और Event Loop

16. async function में `await` क्या करता है?

  1. Pauses that function until the promise settles
  2. Blocks the whole page
  3. Cancels the promise
  4. Runs code twice
जवाब देखें

जवाब: Pauses that function until the promise settles

इंतज़ार के दौरान बाकी code चलता रहता है।

पाठ: JSON, Regex और Event Loop

17. setTimeout(fn, 0) तुरंत क्यों नहीं चलता?

  1. 0 means never
  2. fn is queued until the call stack is clear
  3. setTimeout is synchronous
  4. It needs a promise
जवाब देखें

जवाब: fn is queued until the call stack is clear

Event loop मौजूदा code के बाद queued callbacks चलाता है।

पाठ: JSON, Regex और Event Loop

18. profile के null होने पर user.profile?.name क्या लौटाता है?

  1. undefined
  2. A TypeError
  3. null
  4. ""
जवाब देखें

जवाब: undefined

Optional chaining short-circuit होकर undefined लौटाता है।

पाठ: आधुनिक Syntax: Optional Chaining और अन्य

← कोर्स पर वापस जाएँ