@bento
Frontend Developer
Nothing here yet.
Nothing here yet.
No blogs yet.
Apoorv Tyagi Indeed isPercentage() is but isPercentage isn't. In my opinion functions should be named to the actions they are taking and not what their return values will be, for example getUser, checkNaming , otherwise if you name the function isPercentage what will you name the return value? function isPercentage( val ) { var isInRange = ( val >= 0 && val <= 100 ); return isInRange; } const ??? = isPercentage( 9 ); So the naming for the function above is bad 馃憥 as it implies a boolean type but is a function. Also, that function does not check if a value is a percentage, I'd expect that if a function is called isPercentage it would test if a string contains a value like % or a logic around it. Naming a function like this will lead to confusion and the point of the article is to leave things clean and with good practices, you advocate good practices and explain them in other points but this is not one of them. There's no such thing as boolean functions , it's just a function that returns a boolean . typeof(isPercentage) is function and not boolean .
Thank you for the article. It seems like point 14 example doesn't follow the rules you talk about yourself. For example: function isPercentage ( val ) { ... } This function should be named checkIfInRange or something that makes it more obvious that it is a function. To me as a developer something that is prefixed with is , will most likely be a boolean . In my opinion a better approach at this is: function checkIfInRange ( amount ) { return (amount >= 0 && amount <= 100 ); } const isInRange = checkIfInRange( 78 ); console .log(isInRange); // true