Common JavaScript Errors Explained in Hindi (with Examples)
👋 Hello Developers!
अगर आप JavaScript सीख रहे हैं, तो आपको coding करते समय अक्सर errors का सामना करना पड़ा होगा। ये errors beginners और professionals दोनों के लिए confusing हो सकती हैं।
इस पोस्ट में हम 5 most common JavaScript errors (Syntax, Reference, Type, Range, और JSON Errors) को Hindi में समझेंगे। Examples और solutions के साथ, ताकि आप coding के दौरान इन problems को easily fix कर सकें।
👉 post को end तक ज़रूर पढ़ें, आपको सभी important concepts clear हो जाएंगे।
Table of Contents
-
Syntax Errors
Reference Errors
-
Type Errors
-
Range and Number Errors
-
JSON and Parsing Errors
-
FAQs
-
Related Posts
-
Conclusion
1. Syntax Errors
जब आपके JavaScript code की syntax (grammar rules) गलत होते है तो Syntax Error आता है।
Common Examples
-
Uncaught SyntaxError: Unexpected token
Example:(yaha string close नहीं हुआ)
-
Uncaught SyntaxError: Missing ) after argument list
-
Uncaught SyntaxError: Unexpected end of input
(closing bracket missing है)
-
Uncaught SyntaxError: Invalid or unexpected token
यह error तब आती है जब आप गलत character use करते हैं।
✅ Solution: हमेशा code properly close करें ("
, '
, )
, }
आदि का ध्यान रखें)।
2. Reference Errors
जब आप किसी variable या function को use करने की कोशिश करते हैं जो आपके program में exist ही नहीं करता या सही scope में available नहीं है, तब Reference Error आता है।
Common Examples
-
Uncaught ReferenceError: x is not defined
-
Uncaught ReferenceError: Cannot access 'x' before initialization
यहाँ हम variable को declare करने से पहले use कर रहे है। (Variable hoisting issue)
-
Uncaught ReferenceError: require is not defined (browser में)
ये error आपको node.js के नहीं मिलेगी लेकिन जब आप इसी कोड को browser में रन करेंगे तो आपको error मिलेगी। (require सिर्फ Node.js में चलता है, browser में नहीं)
-
Uncaught ReferenceError: exports is not defined
यह error आपको तब मिलती है जब आप exports keyword की मदद से किसी function को export करते है जो कोड आपका ब्राउज़र में रन होगा तो आपको यह error मिलेगी। (Node.js modules को browser में directly use करने पर आता है)
✅ Solution: Variable declare करने से पहले use ना करें, और environment (Node.js vs Browser) का ध्यान रखें।
3. Type Errors
जब आप किसी value पर गलत type का operation करते हैं, तब Type Error आता है।
Common Examples
-
Uncaught TypeError: Cannot read property 'x' of undefined
-
Uncaught TypeError: Cannot set property 'x' of undefined
-
Uncaught TypeError: x is not a function
-
Uncaught TypeError: Cannot read private member #x from an object
(Private fields को बिना सही declare किए access करने पर आता है) -
Uncaught TypeError: Assignment to constant variable
✅ Solution: Variables और functions सही तरीके से use करें। Undefined values को handle करने के लिए if
conditions या ?.
operator use करें।
4. Range & Number Errors
जब किसी function या operation का value allowed limit से बाहर चला जाता है तब ये errors आते हैं।
Common Examples
-
Uncaught RangeError: Maximum call stack size exceeded
(Infinite recursion होने पर) -
Uncaught RangeError: Invalid array length
-
Uncaught RangeError: toFixed() digits argument must be between 0 and 100
✅ Solution: Functions में सही arguments pass करें और infinite recursion से बचें।
5. JSON & Parsing Errors
जब आप JSON को सही तरीके से format नहीं करते या parse करने में गलती करते हैं तो ये errors आती हैं।
Common Examples
-
Uncaught SyntaxError: Unexpected token in JSON
-
JSON.parse: unexpected character
-
Unexpected end of JSON input
✅ Solution: JSON हमेशा सही format (double quotes, proper brackets) में होना चाहिए।
6. FAQs
Q1: JavaScript Errors क्या होते हैं?
Ans: जब code execute करते समय कोई mistake या invalid operation होता है, तो JavaScript error आती है।
Q2: क्या ये errors browser और Node.js दोनों में आते हैं?
Ans: हाँ, लेकिन कुछ errors environment specific होते हैं (जैसे require is not defined
browser में)।
Q3: JavaScript errors को कैसे debug करें?
Ans: Browser का Developer Console सबसे best tool है debugging के लिए।
7. Related Posts
Conclusion
इन errors को समझना और fix करना JavaScript सीखने का सबसे important हिस्सा है। अब जब भी आपको कोई Syntax Error, Reference Error, Type Error, Range Error या JSON Parsing Error मिले तो आप आसानी से identify और solve कर सकते हैं।
👉 Pro Tip: Browser का Developer Console हमेशा use करें, वहाँ error message clearly show होता है।
💡 If you found this helpful, Share this post और हमारे YouTube channel को Subscribe करना ना भूलें।
0 Comments
Do not enter any spam comments please.