Top 5 Common JavaScript Errors Explained in Hindi | Syntax, Reference, Type, Range & JSON Errors

Common JavaScript Errors Explained in Hindi (with Examples)


Top 5 common JavaScript error explained in hindi



 👋 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

  1. Syntax Errors
  2. Reference Errors

  3. Type Errors

  4. Range and Number Errors

  5. JSON and Parsing Errors

  6. FAQs

  7. Related Posts

  8. Conclusion


1. Syntax Errors

जब आपके JavaScript code की syntax (grammar rules) गलत होते है तो Syntax Error आता है।

Common Examples

  • Uncaught SyntaxError: Unexpected token
    Example:

    let name = "Akshay;

    (yaha string close नहीं हुआ)

  • Uncaught SyntaxError: Missing ) after argument list

    console.log("Hello World";
  • Uncaught SyntaxError: Unexpected end of input

    if (true { console.log("Hello");

    (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

    console.log(x); // x declare ही नहीं किया
  • Uncaught ReferenceError: Cannot access 'x' before initialization

    console.log(x); let x = 10;

    यहाँ हम variable को declare करने से पहले use कर रहे है। (Variable hoisting issue)

  • Uncaught ReferenceError: require is not defined (browser में)

    const fs = require("fs");

    ये 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

    let user; console.log(user.name); // यहाँ name user की property नहीं है
  • Uncaught TypeError: Cannot set property 'x' of undefined

    let user; user.name = "Akshay"; // यहाँ user object नहीं है
  • Uncaught TypeError: x is not a function

    let num = 5; num(); // number को function की तरह call कर दिया
  • Uncaught TypeError: Cannot read private member #x from an object
    (Private fields को बिना सही declare किए access करने पर आता है)

  • Uncaught TypeError: Assignment to constant variable

    const pi = 3.14; pi = 22/7; // const variable को reassign नहीं कर सकते

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 होने पर)

    function test() { test(); // बार-बार खुदको call कर रहा है } test();
  • Uncaught RangeError: Invalid array length

    let arr = new Array(-5); // Negative length invalid है
  • Uncaught RangeError: toFixed() digits argument must be between 0 and 100

    let num = 10.5; console.log(num.toFixed(200)); // 200 limit से बाहर है

Solution: Functions में सही arguments pass करें और infinite recursion से बचें।


5. JSON & Parsing Errors

जब आप JSON को सही तरीके से format नहीं करते या parse करने में गलती करते हैं तो ये errors आती हैं।

Common Examples

  • Uncaught SyntaxError: Unexpected token in JSON

    JSON.parse("{name:'Akshay'}"); // Keys हमेशा double quotes "name" में होनी चाहिए
  • JSON.parse: unexpected character

    JSON.parse("Hello"); // Invalid JSON string
  • Unexpected end of JSON input

    JSON.parse('{"name": "Akshay"'); // Closing bracket missing

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 करना ना भूलें।

common javascript error in hindi


Post a Comment

0 Comments