Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javascript verification of empty or null (is it correct?)

I'm using javascript to do a verification if an input field is empty this way:

if($("#nu_username").val() == null || $("#nu_username").val() == ""){ 
    do action...
}

It works well, but I wonder if it's redundant to use both conditions. Do you know it?

like image 917
sergioviniciuss Avatar asked Jul 13 '12 13:07

sergioviniciuss


1 Answers

Both null and "" are "falsy".

You can write

if (!$('#nu_username').val())
like image 55
SLaks Avatar answered Sep 21 '22 05:09

SLaks