question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Set/Map logged as empty object in editor output

See original GitHub issue

Affected page

Javascript Code Editor

To reproduce

Steps to reproduce the behavior:

  1. Write the following code; const test = new Set([1,2,3,4,5]); console.log("Output:", test);

Expected behavior

Output: Set(5) { 1, 2, 3, 4, 5 }

Screenshots

image

System

  • Device: Laptop
  • OS: Windows 10
  • Browser: Edge
  • Version: 96.0.1054.34

Additional context

https://forum.freecodecamp.org/t/javascript-sets-not-logging-on-freecodecamp-editor/486895

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
ojeytonwilliamscommented, Jan 4, 2022

I dug into this a little bit: the problem is that https://github.com/freeCodeCamp/freeCodeCamp/blob/main/client/src/utils/format.js relies on a fallback https://github.com/browserify/node-util when running in the browser. This fallback does not know how to handle sets or maps and just returns {}.

If anyone wants to work on this, the obvious approach is to check if the input is an instanceof Set or Map and then write some custom code to format them.

1reaction
ShaunSHamiltoncommented, Feb 2, 2022

I take it we are leaving this open, as tests should probably be added?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Javascript Sets not logging on freeCodeCamp editor
Jus try this code in the editor: const test = new Set([1,2,3,4,5]) console.log(test); ... Set/Map logged as empty object in editor output.
Read more >
how to display empty game object in the editor? - Unity Answers
I use empty game objects as reference points, but I find it really hard to position them in the editor because they are...
Read more >
Map & Set • Angular - codecraft.tv
Map is a new data structure introduced in ES6 which lets you map keys to values without the drawbacks of using Objects.
Read more >
How can I Display a JavaScript ES6 Map Object to Console?
The results are always empty object. When I use console.log([...mapObject]);. It prints out an array format.
Read more >
Map Class | Apex Reference Guide - Salesforce Developers
Uniqueness of keys of all other non-primitive types, such as sObject keys, is determined by comparing the objects' field values. Map keys of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found