Function object in JavaScript In Hindi | JS Function object
JavaScript eval() Function In Hindi | JS eval() Function
session Storage In JavaScript In Hindi | JS session Storage In Hindi
Understanding setTimeout In JavaScript | JS setTimeout In Hindi
JavaScript console Object : Window Console Object In Hindi
Features of Laravel 9 : What is new in Laravel 9
PHP Null Coalescing Operator In Hindi , Null Coalescing Operator kya hai ?
PHP com port communication In Hindi | Write on com port in PHP
PHP filter_var() Function In Hindi | filter_var() In PHP In Hindi
If tutorials available on this website are helpful for you, please whitelist this website in your ad blocker😭 or Donate to help us ❤️ pay for the web hosting to keep the website running.
जब भी js engine किसी invalid code को syntactically interpret करता है तो SyntaxError
object एक error को represent करता है। ये error तब throw होती है जब js engine किसी tokens या token order JavaScript language के according syntax follow नहीं करता है।
SyntaxError एक serializable object, इसलिए इसे structuredClone() के साथ clone किया जा सकता है। और SyntaxError , Error
की एक subclass है।
अब जब SyntaxError , Error class की ही एक subclass है तो इसका मतलब है Error class की सभी methods और properties को SyntaxError object के though access किया जा सकता है।
जैसा कि आपको पता है कि eval()
method string में pass की गयी values को calculate करता है , अब अगर हम इसमें numeric values की जगह string pass कर दें तो SyntaxError create होगी।
try {
eval("hello");
}
catch (e) {
console.error(e instanceof SyntaxError);
console.error(e.message);
console.error(e.name);
console.error(e.fileName);
console.error(e.lineNumber);
console.error(e.columnNumber);
console.error(e.stack);
}
Output0
false hello is not defined ReferenceError about:srcdoc line 3 > eval 1 1 @about:srcdoc line 3 > eval:1:1 @about:srcdoc:3:3
SyntaxError को catch करने के लिए normally try catch का use किया गया है। हालाँकि आप चाहे तो manually भी SyntaxError
को throw कर सकते हैं।
try {
throw new SyntaxError("hi", "myfile.js", 10);
}
catch (e) {
console.error(e instanceof SyntaxError);
console.error(e.message);
console.error(e.name);
console.error(e.fileName);
console.error(e.lineNumber);
console.error(e.columnNumber);
console.error(e.stack);
}
Output
false hi ReferenceError myfile.js 10 0 @about:srcdoc:3:9
Loading ...
Hi ! I'm Rahul Kumar Rajput founder of learnhindituts.com. I'm a software developer having more than 4 years of experience. I love to talk about programming as well as writing technical tutorials and blogs that can help to others. I'm here to help you navigate the coding cosmos and turn your ideas into reality, keep coding, keep learning :)
Get connected with me. :) LinkedIn Twitter Instagram Facebook