Equality Operators: == vs. ===
Declare a variable
numNeighboursbased on a prompt input like this:
If there is only 1 neighbour, log to the console 'Only 1 border!' (use loose equality
==for now).Use an
else-ifblock to log 'More than 1 border' in casenumNeighboursis greater than 1.Use an
elseblock to log 'No borders' (this block will be executed whennumNeighboursis 0 or any other value).Test the code with different values of
numNeighbours, including 1 and 0.Change
==to===, and test the code again, with the same values ofnumNeighbours. Notice what happens when there is exactly 1 border! Why is this happening?Finally, convert
numNeighboursto a number, and watch what happens now when you input 1.Reflect on why we should use the
===operator and type conversion in this situation.