Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Constructor function show array literals [] instead of {} #47556

Closed
phil151again opened this issue Apr 14, 2023 · 4 comments
Closed

Constructor function show array literals [] instead of {} #47556

phil151again opened this issue Apr 14, 2023 · 4 comments

Comments

@phil151again
Copy link

phil151again commented Apr 14, 2023

Version

18.7.0

Platform

Linux nyufo-Aspire-A315-34 5.19.0-38-generic #39-Ubuntu SMP PREEMPT_DYNAMIC Fri Mar 17 17:33:16 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

Subsystem

No response

What steps will reproduce the bug?

const stringExample = new String('Hello World')

console.log(stringExample)
console.log(typeof stringExample)

How often does it reproduce? Is there a required condition?

No response

What is the expected behavior? Why is that the expected behavior?

No response

What do you see instead?

in the latest Firefox show curly brackets, but in node in console show array literals

Additional information

No response

@phil151again phil151again changed the title Constructor function show array literals ([]) Constructor function show array literals [] instead of {} Apr 14, 2023
@phil151again
Copy link
Author

//another issue:
const testNumber = new Number(12)
console.log(testNumber.valueOf)

/* in Firefox reurns 12, in Node return [Function: valueOf]
*/

@VoltrexKeyva
Copy link
Member

I can't reproduce the original issue, I'm not even sure what you're referring to because the output is:

[String: 'Hello World']
object

If you're referring to the [] around the first output, there's no issue here as the output of anything being logged is implementation-defined. Node.js follows the console specification by WHATWG, the console.log() method uses a printer, and the said printer's output is implementation-defined as described here:

The logger operation accepts a log level and a list of other arguments. Its main output is the implementation-defined side effect of printing the result to the console. This specification describes how it processes format specifiers while doing so.

@VoltrexKeyva
Copy link
Member

//another issue:
const testNumber = new Number(12)
console.log(testNumber.valueOf)

/* in Firefox reurns 12, in Node return [Function: valueOf]
*/

Node.js is correct here as %Number.prototype.valueOf()% is a method and not a getter as described in the JavaScript specification here.

@aduh95
Copy link
Contributor

aduh95 commented Apr 14, 2023

//another issue: const testNumber = new Number(12) console.log(testNumber.valueOf)

/* in Firefox reurns 12, in Node return [Function: valueOf] */

In Firefox, I get function valueof, not 12.

in the latest Firefox show curly brackets, but in node in console show array literals

Here's the output I get on Firefox:

String { "Hello World" }
object

As @VoltrexKeyva said, the output of console.log is implementation-defined, it's expected to see discrepancies. Node.js doesn't show an array literal, it uses square brackets.

I'm going to close the issue because I believe there's nothing to be done on Node.js side, but don't hesitate to ask more questions.

@aduh95 aduh95 closed this as not planned Won't fix, can't repro, duplicate, stale Apr 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants