Skip to content

Spot the bug solutions

const newsletter = "Bytes"
- const tagline = "Your weekly dose of JavaScript"
+ const tagline = "Your weekly dose of JavaScript";
[newsletter, tagline].forEach((el) => console.log(el))

You need a semi-colon

interpreted as

"Your weekly dose of JavaScript"[(newsletter, tagline)].forEach();

The problem with None in Python

def min(iterable, default=None):
    """Imperfect re-implementation of Python's built-in min function."""
    minimum = None
    for item in iterable:
        if minimum is None or item < minimum:
            minimum = item
    if minimum is not None:
        return minimum
    elif default is not None:
        return default
    else:
        raise ValueError("Empty iterable")

2 bugs that stem from how we're using None to check for undefined both times

>>> min([None], default=0)
0
>>> min([None])
ValueError: Empty iterable
>>> min([1,2,3], default=None)
ValueError: Empty iterable

Last update: 2022-11-04