From d5167630f65a38395bbc5d056f2db01d75ebf2fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sind=C3=A9lio=20Henrique=20Lima?= Date: Thu, 26 Dec 2024 19:38:54 -0300 Subject: [PATCH] Add more type examples for the typeof operator in JavaSccript This PR: - Adds more type examples with the typeof operator in JavaSccript This is relevant as the article is targeted to JavaScript programmers. --- .../copy/en/get-started/TS for JS Programmers.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/documentation/copy/en/get-started/TS for JS Programmers.md b/packages/documentation/copy/en/get-started/TS for JS Programmers.md index 4d1ec984241a..c7ee57648ed3 100644 --- a/packages/documentation/copy/en/get-started/TS for JS Programmers.md +++ b/packages/documentation/copy/en/get-started/TS for JS Programmers.md @@ -159,11 +159,16 @@ To learn the type of a variable, use `typeof`: | string | `typeof s === "string"` | | number | `typeof n === "number"` | | boolean | `typeof b === "boolean"` | +| null | `typeof null === "object"` | | undefined | `typeof undefined === "undefined"` | +| object | `typeof o === "object"` | | function | `typeof f === "function"` | | array | `Array.isArray(a)` | +| symbol | `typeof s === "symbol"` | +| bigint | `typeof b === "bigint"` | -For example, you can make a function return different values depending on whether it is passed a string or an array: +You might be wondering why `typeof null` is `object` in JavaScript, and that is an historical accident which will be mentioned again later. +Back to unions, you can make a function return different values depending on whether it is passed a string or an array: ```ts twoslash