Global Variables Out of Functions

https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/functional-programming/refactor-global-variables-out-of-functions

Hey, guys for this challenge took me a while to understand thoroughly, but for the if conditional statement line which is if (newArr.indexOf(bookname) >=0)
I understand that it is checking if it exists, but I’m not sure why >=0? Is it a truthy or falsey type of thing?

The main goal of this lesson is to avoid altering the variables outside the functions, so what you have to do is find a way to work with a global variable inside the function without altering it.

Correct, that I understand, I just didn’t quite get the syntax here. I understand that the condition checks if it exist or not. It returns -1 which is false, which then removes the specific item from the list. Just needed a breakdown…

if (newArr.indexOf(bookName) >=0)
newArr.splice(newArr.indexOf(bookName),1);

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.