Is there a convention for naming mutable and predicate functions in Javascript?
For example, in Ruby, Lisp, etc., functions that mutate their contents, like gsub!, usually have an exclamation point as a convention to denote that the function is dangerous.
Or, if the function returns a boolean value, like even?, the function will have a question mark.
Unfortunately, you can’t use special characters like ? or ! in function names in Javascript, so what conventions do Javascript programmers use to denote these special types?
Yes, the usual convention for naming a function that returns
true|falseis to prefix it withis, as inisDate,isHidden… As for methods that mutate there’s no convention AFAIK, but in JavaScript most methods don’t modify the original object, so you just need to know which ones do and which ones don’t, but you’ll be able to tell. For examplereplacedoesn’t modify the original object so you can tell because of the assignment:a = a.replace(...), but a method likesplicedoes modify the original object, so you can tell because there’s no assignment on the same variable.