I'm new to jQuery and im just trying to pass a boolean to a function.Ive tried various amendments but still not working ?
I'm expecting the alert to be fired
isTrue(true); function isTrue(boolean isNot){ if(isNot){ alert('true'); } }
Boolean params make code harder to read To understand what this code does, you need to jump to the function implementation. Or at least to see its signature. This adds friction. It makes code a little harder to read.
static Boolean valueOf(boolean b) : This method returns a Boolean instance representing the specified boolean value. If the specified boolean value is true, it returns Boolean. TRUE or if it is false, then this method returns Boolean.
Flags are not a best practice because they reduce the cohesion of a function. It does more than one thing. Booleans make it hard to understand what a function does based on the call site. Single argument functions and passing an object with named values improves the readability.
JavaScript (not Java) has no type indicators, just variable names. Remove boolean
function isTrue(isNot){ if(isNot){ alert('true'); } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With