Hey everyone,
I have a question. I started learning JS and i have been a task to solve. The task is Not the problem. My solution checks for strict equality between indexOf and 0 in the if condition. While the sample solution checks for inequality on strike. So indexOf and -1. My question is, is it more correct to check for inequality (so -1) or equality (so 0)?
If (variable.indexOf(variable) === 0)
Or
If(variable.indexOf(variable) !== -1)
I have a question. I started learning JS and i have been a task to solve. The task is Not the problem. My solution checks for strict equality between indexOf and 0 in the if condition. While the sample solution checks for inequality on strike. So indexOf and -1. My question is, is it more correct to check for inequality (so -1) or equality (so 0)?
If (variable.indexOf(variable) === 0)
Or
If(variable.indexOf(variable) !== -1)