typeof: checking a value category
typeof returns a string describing a JavaScript value category. It helps identify primitive types but does not distinguish every kind of object.
CKTIS / JavaScript
Programming syntax, operators and concepts. Find an explanation, explore an example and return to learning.
typeof returns a string describing a JavaScript value category. It helps identify primitive types but does not distinguish every kind of object.
Unary minus (`unary minus`), written as `-expression`, converts its operand to a numeric value and returns its negation. It supports both `Number` and `BigInt`; it does not assign the result back to the variable.
The >>> operator shifts a number’s 32-bit representation to the right, inserting zeros on the left. It returns a nonnegative Number, and the shift count is reduced modulo 32. It does not support BigInt.
The >>>= operator shifts a value’s 32-bit representation to the right, fills vacated bits with zeros, and stores the result in the left operand. Unlike >>=, it does not preserve the sign bit. It does not support BigInt.
The unary `void` operator evaluates its operand, discards its value, and produces `undefined`. It preserves side effects and does not catch exceptions. The expression `void 0` provides the value `undefined`.
arguments exposes the arguments supplied to a function call. It has indexed properties and length but is not an array. Parameter aliasing depends on strict mode and the parameter list; arrow functions do not create their own arguments.
An arrow function is an expression that creates a function using =>. It can implicitly return an expression's result and uses this from its surrounding context rather than establishing its own this when called.
A BigInt literal is an integer written with a lowercase n suffix, such as 42n. It creates a bigint value without the rounding that affects large Number values.
Square brackets in a property or method definition let an expression determine its key. The key is established when the object is created; changing the variable used in that expression later does not rename the property.
A default parameter uses its initializer when an argument is omitted or explicitly passed as undefined. Values such as null, 0, false, and an empty string do not trigger the default.
Destructuring reads object properties or successive iterable values through a pattern. It supports declaring variables, assigning to existing variables, renaming bindings, supplying defaults, and collecting remaining values or properties.
A generator function creates an iterator whose execution can pause at yield and resume through next(). It computes values on demand while preserving local state between successive steps.
A hexadecimal numeric literal writes a number in base 16 using the prefix 0x or 0X. Without a suffix it creates a Number value; the n suffix indicates BigInt.
An IIFE creates a function and calls it immediately. It runs code in its own function scope, accepts arguments, and returns a result without a separate function declaration.
A method definition writes a method without the function keyword or a colon. Its this value depends on how it is called.
Object property shorthand lets you write `{ name }` instead of `{ name: name }`: the identifier's name becomes the key, and its current value becomes the property's value. The exception is `__proto__`: `{ __proto__ }` creates an own data property from the binding's value, while `{ __proto__: __proto__ }` uses object-literal prototype-setter syntax and does not create that property.
A regular expression literal (RegExp literal) writes a pattern directly in code as /pattern/flags. It creates a RegExp object that can be used to test text, search for matches, or replace matching text.
Strict mode changes JavaScript syntax and execution rules, exposing some errors that would otherwise be ignored. Enable it with a "use strict" directive; modules and class code are automatically strict.
A template literal uses backticks (`) as delimiters. It supports embedded expressions through ${expression} and multiline text. A tagged variant passes text segments and expression values to a tag function.
Null is a JavaScript primitive type with exactly one value: null. It represents the intentional absence of an object value. Check for it with === null: typeof null returns "object", even though null is not an object.
Object is JavaScript’s non-primitive value type. Objects hold properties and have their own identity; assignment does not copy an object. Arrays and functions are objects too, whereas null is not an object.
Undefined is a primitive JavaScript type with exactly one value: undefined. Learn the difference between the type name, its value, and the string "undefined", and distinguish this value from null.
AbortController communicates a cancellation request through `signal`. `fetch` constructs a `Request` before checking the signal. If request construction fails, the promise rejects with that error (for example, a `TypeError` for an invalid URL), even if the signal is already aborted. If `fetch` detects the abort while its promise is pending, it rejects the promise with the abort reason. If the promise has already fulfilled with a `Response`, aborting cannot change its state but can cause a pending response-body read to fail.
AbortSignal passes a cancellation request to fetch; AbortController initiates cancellation, while the signal exposes its state.