My observations:
- Use
letinstead ofvar. You are already usingletin some places, but a few need to be converted. For those that do not know the difference,letis one of the new features in ES2015 (ES6) and it respects block scopes in the same way as other programming languages. - ~~
- I would use file scope constants for the strings "passenger" and "vehicle". Makes it easier in the future to do refactors. For example, at the top of the file
const PASSENGER = 'passenger' - Change this
if (!(nearest === undefined))toif (!!nearest), what you care about is if its a truthy value. The specificity of "not undefined" would allow other falsy values like0,null,NaN,'',"",\`````` - If file scope constant were to be used and all the possible values are known, you could test for those specifically. Instead of
if (!!nearest)you couldif ([PASSENGER, VEHICLE].includes(nearest))