+ 1

How do I check for null values in JavaScript?

prompt return empty ... is this a null value?

24th Jan 2017, 3:49 AM
Didi Georgel Danaila
Didi Georgel Danaila - avatar
3 odpowiedzi
+ 5
var newVal = prompt("Enter new value:"); if (newVal === "") { alert("user pressed OK, but the input field was empty"); } else if (newVal) { alert("user typed something and hit OK"); } else { alert("user hit cancel");
24th Jan 2017, 4:22 AM
David Sebastian Keshvi Illiakis
David Sebastian Keshvi Illiakis - avatar
+ 4
if (x === null)
24th Jan 2017, 4:14 AM
David Sebastian Keshvi Illiakis
David Sebastian Keshvi Illiakis - avatar
0
I found this on Google, but I don't want to see the "oldVal" var oldVal = 'something'; var newVal = prompt("Enter new value:", oldVal); if (newVal === "") { alert("user pressed OK, but the input field was empty"); } else if (newVal) { alert("user typed something and hit OK"); } else { alert("user hit cancel");
24th Jan 2017, 4:20 AM
Didi Georgel Danaila
Didi Georgel Danaila - avatar