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 Odpowiedź
+ 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