Master JavaScript
What typeof would say
You are building a small teaching tool that sits beside a code editor. The reader types a value, and the tool shows what typeof would answer for it, so they can check their prediction without running anything.
The input is the value as it was typed, so it arrives as text: the four characters null, or the three characters 42n, or the seven characters "hello" including its quotation marks. Your job is to answer with the word typeof would produce.
null gives "object". That is the famous lie, and the tool has to reproduce it.undefined gives "undefined".true or false gives "boolean".NaN or Infinity gives "number".n, such as 42n, gives "bigint".42 or 3.5, gives "number".Symbol( gives "symbol"."string".function gives "function".[ or { gives "object"."unknown".The order matters. null starts with none of the special characters and would otherwise fall through to "unknown", so the exact matches have to be tried first.
Input: "42n"
rule 1 is it exactly null? no
rule 2 is it exactly undefined? no
rule 3 true or false? no
rule 4 NaN or Infinity? no
rule 5 digits then a single n? yes
Output: "bigint"literal is between 1 and 60 characters and has no spaces at either end."object", "undefined", "boolean", "number", "bigint", "string", "symbol", "function", "unknown".Run your code to see how it does on the examples. Submit also runs the hidden cases.