Can we assign "Undefined" as a value to a variable?? Is it a good practice?? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Can we assign "Undefined" as a value to a variable?? Is it a good practice??

22nd Mar 2019, 5:37 AM
Abdul Rasul
Abdul Rasul - avatar
4 Answers
+ 5
Hmm... i think you should use "Not Found" instead of undefined, because undefined is equals to error
22nd Mar 2019, 10:41 AM
Jingga Sona
Jingga Sona - avatar
22nd Mar 2019, 6:09 AM
Sarthak Pokhrel
Sarthak Pokhrel - avatar
+ 2
If you are talking about JavaScript then I think it is not a bad practice. But what you wanna do after assigning undefined to a variable. During declaration of a variable, the default value is undefined.
22nd Mar 2019, 6:07 AM
Sarthak Pokhrel
Sarthak Pokhrel - avatar
+ 1
But "Not found" is a string value that the coder has to explicitly assign it to the variable. And "undefined" is a predefined value, these are two different things, you know.
22nd Mar 2019, 4:46 PM
Abdul Rasul
Abdul Rasul - avatar