Almac
Almac

Reputation: 227

What JavaScript value should you assign to a variable x so that typeof x = = = x would be true?

I've tried assigning different data types such as boolean, numbers, strings, objects, nulls, etc, but keep getting false returned. Any ideas?

Upvotes: 6

Views: 215

Answers (1)

Phrogz
Phrogz

Reputation: 303253

The typeof operator always returns a string value. As such, your original value must be a string. The result of typeof for a string is "string", and so:

x = "string"
typeof x === x // true

Upvotes: 15

Related Questions