Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

boolean argument not passing correctly

Tags:

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');     } } 
like image 627
user701254 Avatar asked May 31 '12 21:05

user701254


People also ask

What is wrong with Boolean parameters?

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.

How do you pass a Boolean value?

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.

Are Boolean flags bad?

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.


1 Answers

JavaScript (not Java) has no type indicators, just variable names. Remove boolean

function isTrue(isNot){     if(isNot){       alert('true');     } } 
like image 146
Joseph Avatar answered Sep 20 '22 02:09

Joseph