0
Undefined Problem
Hey guys... In javascript how to say if the variable is undefined then do nothing or print nothing? I tried the line below but it didn't work! If ( typeof txt === 'undefined' ) { Txt= null; } It still prints the undefined!!! Please help!!
15 Respuestas
+ 4
var a;
if a==undefined
do something
+ 3
if (!txt) {
//do something
}
+ 1
Shaghayegh Hp , you have used three === and put a string, 'undefined'. Either put 2 equal tos or remove the quotes.
+ 1
Arnesh thanks it worked
+ 1
x==null try this 👶 with the if condition
0
Arnesh here is my code, it still dosent work. and prints"undefined"
https://code.sololearn.com/WUE0oR3HX6Z3/?ref=app
0
Shaghayegh Hp , remove the typeof
0
Arnesh it still dosent work!! 🤦♀️
0
typeof work with ()
Ex-
Console.log(typeof(5));
//number
0
Divya Mohan it still dosent work, maybe the other part of my code has a problem, did you check it?
0
What do you want as result that not executing here.
0
Divya Mohan how i can avoid this code from printing "undefined" after adding five comment?
0
Shaghayegh Hp , you didn't say that... :-)
https://code.sololearn.com/W2FRgWaHL2sm/?ref=app
0
How could be the typeof txt be undefined.
It will be always a string that's inside promt box or no comment .
Then why are you making a condition for
typeof(txt)=== 'undefined'
what do you want after clicking button 2
0
I am not a javascript person but I think it is also a case sensitive language for which you have to be sure that the Txt!=txt.
Moreover, I respect your question but, you could check it by printing in the if the condition to get sure about the condition.
Hope you understand what I mean.
And after correction please mention that if there is == or === in javascript as I believe there must be two equals and the text has to be in a string like "undefined".