To check an empty field is need null and ""?


if ($(this).val() == null || $(this).val() == '') {
  // do
 <input value="">

Both gives back false?

I saw many tutorial have in this to check for sure the field is empty but why need both? Can anyone explain? Why not just with null? Thanks!

Since the val is a string, you can just check whether it’s truthy. Any non-empty string is considered truthy

if ($(this).val()) { ... do stuff ... }
1 Like