Error handling any one can explain me this code | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Error handling any one can explain me this code

// Pretend this is coming from a server as response let a = "Harry bhai"; a = undefined; if (a !=undefined) { throw new Error('This is not undefined'); } else { console.log('This is undefined'); }

4th Sep 2022, 12:22 PM
Abhishek
Abhishek - avatar
1 Answer
+ 2
If a is not undefind, JS crash with the error ('this is not undefined') If you don't want program crash, surround the block with try/catch
4th Sep 2022, 1:35 PM
Roland
Roland - avatar