Logging Values With Their Names

With console.dir(), you can see all of Joan’s nested result, but most debugging is smaller than that. Say the total in checkRows() drifts from the 125 Joan expects, and you want to see total and donor on each pass of the loop.

In Python, you’d drop in a print() with an f-string. JavaScript’s version of that habit makes every logged value say what it is.

Label Each Value With Braces

Python’s self-documenting f-string writes each name next to its value:

Language: Python
total = 125
donor = "D-101"
print(f"{total=} {donor=}")

Python prints total=125 donor='D-101'. Template literals have no = form, so watch out for carrying ${total=} across. A ${} placeholder takes only an expression, and total= isn’t one, so the whole file stops with SyntaxError: Unexpected token '}'.

The JavaScript way wraps the names in braces instead. Writing { total } is object shorthand, which builds an object with a total property holding the value of total. Here’s the same check with console.log():

Language: JavaScript
const total = 125;
const donor = "D-101";
console.log({ total });
console.log({ total, donor });

Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Locked learning resources

The full lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Become a Member to join the conversation.