typeof Object(1n) === "object" because that's what the Object constructor
does: it creates an object. It's the same for other primitives, e.g. typeof
Object(1) or typeof Object("foo") or typeof Object(true) are all "object".And of course, typeof 1n === "bigint" because what else would it be? There's nothing specific about BigInt in any of these examples, it's exactly the same for Numbers and Strings and other primitives. And AFAICT there's no inconsistency either, this is just how JavaScript works. 1.__proto__ is a SyntaxError because 1. is a Number, and you can't just write __proto__ after a Number literal. Try 1..__proto__ or, equivalently, (1).__proto__ to make it work. On Fri, Jul 14, 2023 at 9:37 AM Shang Yu <[email protected]> wrote: > update > > Hi guys, > Have a look at following code > > let bigint = Object(1n) > console.log(1n.__proto__===bigint.__proto__) > console.log(typeof 1n) > console.log(typeof bigint) > > the output is > true // A > bigint // B > object // C > why while at A is true but at B is bigint (not the expected object)? or > why at C is not bigint? > > *DELETED* > > *If when 1n.__proto__ is evaluated, the 1n is implicitly converted to an > Object, why the following code does not work?1.__proto__ // SyntaxError: > Invalid or unexpected token* > > Many thanks! > 在2023年7月14日星期五 UTC+8 15:25:14<Shang Yu> 写道: > >> Hi guys, >> Have a look at following code >> >> let bigint = Object(1n) >> console.log(1n.__proto__===bigint.__proto__) >> console.log(typeof 1n) >> console.log(typeof bigint) >> >> the output is >> true // A >> bigint // B >> object // C >> why while at A is true but at B is bigint (not the expected object)? or >> why at C is not bigint? >> If when 1n.__proto__ is evaluated, the 1n is implicitly converted to an >> Object, why the following code does not work? >> 1.__proto__ // SyntaxError: Invalid or unexpected token >> Many thanks! >> >> -- -- v8-dev mailing list [email protected] http://groups.google.com/group/v8-dev --- You received this message because you are subscribed to the Google Groups "v8-dev" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/v8-dev/CAKSzg3QzvYhJ6O-kmh1Na%2Bm2%3DOkuA84qqajck01AG1eV9TvScQ%40mail.gmail.com.
