Answer the question
In order to leave comments, you need to log in
Why in libraries does the _findIndex() collection search function return -1 when there are no results, and not NULL?
Why does the _findIndex() collection search function in libraries return -1 when there are no results, and not null?
Is there anything other than (null == 0) in this?
Understanding that it is good practice to use === instead of ==, the reason for returning -1 is unclear.
Several libraries revealed why exactly -1, while the _find () function, which should return an object from the collection, expectedly returns null.
Answer the question
In order to leave comments, you need to log in
Because Array.indexOf returns -1 and libraries honor tradition.
In those distant times, when JS was invented, C was in use, in which there is no null, but NULL===0.
In general, the reasons are historical.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question