Reputation: 2867
As a non-english developer, I often wonder why some javascript functions take a "s" and others don't.
Example:
Array.includes()
Element.contains()
I could figure it's because they are verbs conjugated in the third person. But in that case, why don't the following conjugate?
Array.reduce()
Array.find()
Array.map()
Is there some rule I'm unaware of, or is it just a question of what sounds better for the developer who first writes a library?
Upvotes: 3
Views: 79
Reputation: 1926
As someone who was an English teacher, I'll firstly say that the main reason this is the case is because English kinda sucks. The grammar is weird, and no matter how many rules you memorize, you'll never speak it absolutely perfectly. Even us native speakers struggle with grammar on a daily basis.
To answer your question thoroughly:
includes()
and contains()
are statements that describe the array/value and return a "yes" or a "no" (a true
or false
) statement.English:
My shopping list includes bacon. Is this true?
JavaScript:
const includesBacon = shoppingList.includes('bacon');
console.log(includesBacon); // -> boolean
reduce()
and map()
perform an action on the array/value. You are literally commanding the array to do something to itself.English:
Please map out a new shopping list based on the old, but all bacon. Now!
JavaScript:
shoppingList.map(() => 'bacon')
Upvotes: 4