JavaScript / TypeScript Learning Tool

JavaScript Value and Type Simulator

Explore the differences between undefined, null, 0, false, empty strings, type inference, any, unknown, == and ===, and || and ??.
Choose values and see the results immediately.

Uses: …

Code // results are shown as comments Ready to copy

What the result means

How to use this tool

Choose a mode above, then select values or types to update the code and explanation.
In JavaScript conditions, having a value and being truthy are not the same thing.
The TypeScript checker is a simplified learning model. It does not run the TypeScript compiler, and real results can vary with settings such as strictNullChecks.

Frequently asked questions

What is the difference between undefined and null?

undefined usually means a value has not been assigned, while null is an explicit value used to represent an intentional absence. typeof undefined is “undefined”; typeof null is “object” for historical reasons. Loose equality treats them as equal, but strict equality does not.

Should I use == or ===?

=== compares both value and type without coercion. == may convert types before comparing, which can produce surprising results such as 0 == an empty string. Prefer === unless you specifically need loose equality.

What is the difference between any and unknown?

any disables most type checking, so unsafe operations are allowed. unknown accepts values of any type, but you must narrow the type before using them. Prefer unknown when the type is not yet known.

When should I use the || or ?? operator?

|| uses the fallback for any falsy left-hand value, including false, 0, an empty string, null, undefined, and NaN. ?? uses it only for null or undefined, so it preserves valid values such as 0 and an empty string.

Why are empty arrays and objects truthy?

In JavaScript, arrays and objects are truthy because they are objects, even when they contain no items or properties. To check whether an array is empty, inspect its length; for an object, you can check Object.keys(value).length.

日本語版はこちら

Please also review the Terms of Use for this web app before using it.

Found a bug or have feedback? Let us know here.

Report bugs, display issues, usability problems, or suggestions for improvement.
Consent
– This form is for bug reports only. In principle, we do not respond to individual submissions.
– If a submission contains defamatory, threatening, or otherwise inappropriate content, we may take appropriate action based on logs such as IP addresses.