0

I'm currently using javascript code on my blade.php (Laravel) page and I have a strange error: My != is not accepted:

if({{ $CurrentProduct->disposable_quantity }} != null) {
    if (newQty > {{ $CurrentProduct->disposable_quantity }}) {
        $('input[name="quantity"]').val({{ $CurrentProduct -> disposable_quantity }});
    }
}

If I put a == my code no longer contains errors. I don't understand

Mosh Feu
  • 28,354
  • 16
  • 88
  • 135
dolor3sh4ze
  • 925
  • 1
  • 7
  • 25

1 Answers1

1

If you truly want to confirm that a variable is not null and not an empty string specifically, you would write :

if({{ $CurrentProduct->disposable_quantity }} !== null) {
   // do something
}

I changed your code to check for type equality (!==|===).
You can also use below simple code :

if(Boolean({{ $CurrentProduct->disposable_quantity }} )){ 
  // do something 
}

Note : Values that are intuitively empty, like 0, an empty string, null, undefined, and NaN, become false
Other values become true

STA
  • 30,729
  • 8
  • 45
  • 59