{"componentChunkName":"component---src-templates-documentation-tsx","path":"/docs/handbook/basic-types.html","result":{"data":{"allSitePage":{"nodes":[{"path":"/dev-404-page/"},{"path":"/docs/handbook/nightly-builds.html"},{"path":"/docs/handbook/declaration-files/by-example.html"},{"path":"/docs/handbook/declaration-files/consumption.html"},{"path":"/docs/handbook/declaration-files/deep-dive.html"},{"path":"/docs/handbook/declaration-files/do-s-and-don-ts.html"},{"path":"/docs/handbook/declaration-files/introduction.html"},{"path":"/docs/handbook/declaration-files/library-structures.html"},{"path":"/docs/handbook/declaration-files/publishing.html"},{"path":"/docs/handbook/declaration-files/templates.html"},{"path":"/docs/handbook/typescript-in-5-minutes-func.html"},{"path":"/docs/handbook/typescript-in-5-minutes.html"},{"path":"/docs/handbook/typescript-in-5-minutes-oop.html"},{"path":"/docs/handbook/typescript-from-scratch.html"},{"path":"/docs/handbook/basic-types.html"},{"path":"/docs/handbook/classes.html"},{"path":"/docs/handbook/enums.html"},{"path":"/docs/handbook/functions.html"},{"path":"/docs/handbook/generics.html"},{"path":"/docs/handbook/interfaces.html"},{"path":"/docs/handbook/literal-types.html"},{"path":"/docs/handbook/intro.html"},{"path":"/docs/handbook/unions-and-intersections.html"},{"path":"/docs/handbook/declaration-files/dts-from-js.html"},{"path":"/docs/handbook/intro-to-js-ts.html"},{"path":"/docs/handbook/jsdoc-supported-types.html"},{"path":"/docs/handbook/type-checking-javascript-files.html"},{"path":"/docs/handbook/compiler-options-in-msbuild.html"},{"path":"/docs/handbook/compiler-options.html"},{"path":"/docs/handbook/configuring-watch.html"},{"path":"/docs/handbook/integrating-with-build-tools.html"},{"path":"/docs/handbook/project-references.html"},{"path":"/docs/handbook/tsconfig-json.html"},{"path":"/docs/handbook/advanced-types.html"},{"path":"/docs/handbook/declaration-merging.html"},{"path":"/docs/handbook/decorators.html"},{"path":"/docs/handbook/iterators-and-generators.html"},{"path":"/docs/handbook/jsx.html"},{"path":"/docs/handbook/mixins.html"},{"path":"/docs/handbook/module-resolution.html"},{"path":"/docs/handbook/modules.html"},{"path":"/docs/handbook/namespaces-and-modules.html"},{"path":"/docs/handbook/namespaces.html"},{"path":"/docs/handbook/symbols.html"},{"path":"/docs/handbook/triple-slash-directives.html"},{"path":"/docs/handbook/type-compatibility.html"},{"path":"/docs/handbook/type-inference.html"},{"path":"/docs/handbook/utility-types.html"},{"path":"/docs/handbook/variable-declarations.html"},{"path":"/docs/handbook/release-notes/typescript-1-1.html"},{"path":"/docs/handbook/release-notes/typescript-1-3.html"},{"path":"/docs/handbook/release-notes/typescript-1-4.html"},{"path":"/docs/handbook/release-notes/typescript-1-5.html"},{"path":"/docs/handbook/release-notes/typescript-1-6.html"},{"path":"/docs/handbook/release-notes/typescript-1-7.html"},{"path":"/docs/handbook/release-notes/typescript-1-8.html"},{"path":"/docs/handbook/release-notes/typescript-2-0.html"},{"path":"/docs/handbook/release-notes/typescript-2-1.html"},{"path":"/docs/handbook/release-notes/typescript-2-2.html"},{"path":"/docs/handbook/release-notes/typescript-2-3.html"},{"path":"/docs/handbook/release-notes/typescript-2-4.html"},{"path":"/docs/handbook/release-notes/typescript-2-5.html"},{"path":"/docs/handbook/release-notes/typescript-2-6.html"},{"path":"/docs/handbook/release-notes/typescript-2-7.html"},{"path":"/docs/handbook/release-notes/typescript-2-8.html"},{"path":"/docs/handbook/release-notes/typescript-2-9.html"},{"path":"/docs/handbook/release-notes/typescript-3-0.html"},{"path":"/docs/handbook/release-notes/typescript-3-1.html"},{"path":"/docs/handbook/release-notes/typescript-3-2.html"},{"path":"/docs/handbook/release-notes/typescript-3-3.html"},{"path":"/docs/handbook/release-notes/typescript-3-4.html"},{"path":"/docs/handbook/release-notes/typescript-3-5.html"},{"path":"/docs/handbook/release-notes/typescript-3-6.html"},{"path":"/docs/handbook/release-notes/typescript-3-7.html"},{"path":"/docs/handbook/release-notes/typescript-3-8.html"},{"path":"/docs/handbook/release-notes/typescript-3-9.html"},{"path":"/docs/handbook/asp-net-core.html"},{"path":"/docs/handbook/angular.html"},{"path":"/docs/handbook/babel-with-typescript.html"},{"path":"/docs/handbook/dom-manipulation.html"},{"path":"/docs/handbook/gulp.html"},{"path":"/docs/handbook/migrating-from-javascript.html"},{"path":"/docs/handbook/react.html"},{"path":"/docs/handbook/typescript-tooling-in-5-minutes.html"},{"path":"/vo/docs/handbook/basic-types.html"},{"path":"/docs/handbook/declaration-files/templates/global-modifying-module-d-ts.html"},{"path":"/docs/handbook/declaration-files/templates/global-plugin-d-ts.html"},{"path":"/docs/handbook/declaration-files/templates/global-d-ts.html"},{"path":"/docs/handbook/declaration-files/templates/module-class-d-ts.html"},{"path":"/docs/handbook/declaration-files/templates/module-function-d-ts.html"},{"path":"/docs/handbook/declaration-files/templates/module-plugin-d-ts.html"},{"path":"/docs/handbook/declaration-files/templates/module-d-ts.html"},{"path":"/docs/handbook/release-notes/overview.html"},{"path":"/tsconfig"},{"path":"/en/tsconfig"},{"path":"/vo/tsconfig"},{"path":"/ja/tsconfig"},{"path":"/pt/tsconfig"},{"path":"/play"},{"path":"/en/play"},{"path":"/es/play"},{"path":"/ja/play"},{"path":"/pt/play"},{"path":"/vo/play"},{"path":"/zh/play"},{"path":"/fa/play"},{"path":"/play/3-7/fixits/big-number-literals.ts"},{"path":"/play/3-7/fixits/const-to-let.ts"},{"path":"/play/3-7/fixits/infer-from-usage-changes.ts"},{"path":"/play/3-7/syntax-and-messaging/flattened-error-reporting.ts"},{"path":"/play/3-7/syntax-and-messaging/nullish-coalescing.ts"},{"path":"/play/3-7/syntax-and-messaging/optional-chaining.ts"},{"path":"/play/3-7/types-and-code-flow/assertion-functions.ts"},{"path":"/play/3-7/types-and-code-flow/recursive-type-references.ts"},{"path":"/play/3-7/types-and-code-flow/uncalled-function-checks.ts"},{"path":"/play/3-8/breaking-changes/checking-unions-with-index-signatures.ts"},{"path":"/play/3-8/jsdoc-improvements/accessibility-modifiers.js"},{"path":"/play/3-8/syntax-and-messaging/export-modules-from.ts"},{"path":"/play/3-8/syntax-and-messaging/private-class-fields.ts"},{"path":"/play/4-0/new-checks/class-constructor-code-flow.ts"},{"path":"/play/4-0/new-js-features/jsdoc-deprecated.ts"},{"path":"/play/4-0/new-js-features/logical-operators-and-assignment.ts"},{"path":"/play/4-0/new-js-features/nullish-coalescing.ts"},{"path":"/play/4-0/new-ts-features/named-tuples.ts"},{"path":"/play/4-0/new-ts-features/unknown-in-catch.ts"},{"path":"/play/4-0/new-ts-features/variadic-tuples.ts"},{"path":"/play/javascript/external-apis/typescript-with-deno.ts"},{"path":"/play/javascript/external-apis/typescript-with-node.js"},{"path":"/play/javascript/external-apis/typescript-with-web.js"},{"path":"/play/javascript/external-apis/typescript-with-webgl.js"},{"path":"/play/javascript/functions-with-javascript/function-chaining.ts"},{"path":"/play/javascript/functions-with-javascript/generic-functions.ts"},{"path":"/play/javascript/functions-with-javascript/typing-functions.ts"},{"path":"/play/javascript/helping-with-javascript/errors.ts"},{"path":"/play/javascript/helping-with-javascript/quick-fixes.ts"},{"path":"/play/javascript/javascript-essentials/code-flow.ts"},{"path":"/play/javascript/javascript-essentials/functions.ts"},{"path":"/play/javascript/javascript-essentials/hello-world.ts"},{"path":"/play/javascript/javascript-essentials/objects-and-arrays.ts"},{"path":"/play/javascript/modern-javascript/async-await.ts"},{"path":"/play/javascript/modern-javascript/immutability.ts"},{"path":"/play/javascript/modern-javascript/import-export.ts"},{"path":"/play/javascript/modern-javascript/jsdoc-support.js"},{"path":"/play/javascript/working-with-classes/classes-101.ts"},{"path":"/play/javascript/working-with-classes/generic-classes.ts"},{"path":"/play/javascript/working-with-classes/mixins.ts"},{"path":"/play/javascript/working-with-classes/this.ts"},{"path":"/play/playground/config/javascript-playgrounds.js"},{"path":"/play/playground/config/new-compiler-defaults.ts"},{"path":"/play/playground/language/automatic-type-acquisition.ts"},{"path":"/play/playground/language/fixits.ts"},{"path":"/play/playground/tooling/mobile-support.ts"},{"path":"/play/playground/tooling/sharable-urls.ts"},{"path":"/play/playground/tooling/typescript-versions.ts"},{"path":"/play/typescript/language/soundness.ts"},{"path":"/play/typescript/language/structural-typing.ts"},{"path":"/play/typescript/language/type-guards.ts"},{"path":"/play/typescript/language/type-widening-and-narrowing.ts"},{"path":"/play/typescript/language-extensions/enums.ts"},{"path":"/play/typescript/language-extensions/nominal-typing.ts"},{"path":"/play/typescript/language-extensions/types-vs-interfaces.ts"},{"path":"/play/typescript/meta-types/conditional-types.ts"},{"path":"/play/typescript/meta-types/discriminate-types.ts"},{"path":"/play/typescript/meta-types/indexed-types.ts"},{"path":"/play/typescript/meta-types/mapped-types.ts"},{"path":"/play/typescript/primitives/any.ts"},{"path":"/play/typescript/primitives/literals.ts"},{"path":"/play/typescript/primitives/union-and-intersection-types.ts"},{"path":"/play/typescript/primitives/unknown-and-never.ts"},{"path":"/play/typescript/type-primitives/built-in-utility-types.ts"},{"path":"/play/typescript/type-primitives/nullable-types.ts"},{"path":"/play/typescript/type-primitives/tuples.ts"},{"path":"/es/play/javascript/external-apis/typescript-with-deno.ts"},{"path":"/es/play/javascript/external-apis/typescript-with-node.js"},{"path":"/es/play/javascript/external-apis/typescript-with-web.js"},{"path":"/es/play/javascript/functions-with-javascript/function-chaining.ts"},{"path":"/es/play/javascript/functions-with-javascript/generic-functions.ts"},{"path":"/es/play/javascript/javascript-essentials/hello-world.ts"},{"path":"/es/play/javascript/javascript-essentials/objects-and-arrays.ts"},{"path":"/es/play/typescript/language/soundness.ts"},{"path":"/es/play/typescript/language/structural-typing.ts"},{"path":"/es/play/typescript/language/type-guards.ts"},{"path":"/es/play/typescript/language/type-widening-and-narrowing.ts"},{"path":"/es/play/typescript/meta-types/conditional-types.ts"},{"path":"/es/play/typescript/meta-types/discriminate-types.ts"},{"path":"/es/play/typescript/meta-types/indexed-types.ts"},{"path":"/es/play/typescript/meta-types/mapped-types.ts"},{"path":"/es/play/typescript/primitives/any.ts"},{"path":"/es/play/typescript/primitives/literals.ts"},{"path":"/es/play/typescript/primitives/union-and-intersection-types.ts"},{"path":"/es/play/typescript/primitives/unknown-and-never.ts"},{"path":"/es/play/typescript/type-primitives/built-in-utility-types.ts"},{"path":"/es/play/typescript/type-primitives/nullable-types.ts"},{"path":"/es/play/typescript/type-primitives/tuples.ts"},{"path":"/fa/play/javascript/javascript-essentials/hello-world.ts"},{"path":"/ja/play/3-7/fixits/big-number-literals.ts"},{"path":"/ja/play/3-7/syntax-and-messaging/nullish-coalescing.ts"},{"path":"/ja/play/3-7/syntax-and-messaging/optional-chaining.ts"},{"path":"/ja/play/3-8/breaking-changes/checking-unions-with-index-signatures.ts"},{"path":"/ja/play/javascript/external-apis/typescript-with-deno.ts"},{"path":"/ja/play/typescript/language-extensions/enums.ts"},{"path":"/ja/play/typescript/language-extensions/nominal-typing.ts"},{"path":"/ja/play/typescript/language-extensions/types-vs-interfaces.ts"},{"path":"/ja/play/typescript/primitives/any.ts"},{"path":"/ja/play/typescript/primitives/literals.ts"},{"path":"/ja/play/typescript/primitives/union-and-intersection-types.ts"},{"path":"/ja/play/typescript/primitives/unknown-and-never.ts"},{"path":"/ja/play/typescript/type-primitives/built-in-utility-types.ts"},{"path":"/ja/play/typescript/type-primitives/nullable-types.ts"},{"path":"/ja/play/typescript/type-primitives/tuples.ts"},{"path":"/pt/play/javascript/javascript-essentials/code-flow.ts"},{"path":"/pt/play/javascript/javascript-essentials/functions.ts"},{"path":"/pt/play/javascript/javascript-essentials/hello-world.ts"},{"path":"/pt/play/javascript/javascript-essentials/objects-and-arrays.ts"},{"path":"/vo/play/javascript/javascript-essentials/code-flow.ts"},{"path":"/vo/play/javascript/javascript-essentials/functions.ts"},{"path":"/vo/play/javascript/javascript-essentials/hello-world.ts"},{"path":"/vo/play/javascript/javascript-essentials/objects-and-arrays.ts"},{"path":"/zh/play/javascript/external-apis/typescript-with-deno.ts"},{"path":"/zh/play/javascript/external-apis/typescript-with-node.js"},{"path":"/zh/play/javascript/external-apis/typescript-with-web.js"},{"path":"/zh/play/javascript/external-apis/typescript-with-webgl.js"},{"path":"/zh/play/javascript/functions-with-javascript/function-chaining.ts"},{"path":"/zh/play/javascript/functions-with-javascript/generic-functions.ts"},{"path":"/zh/play/javascript/functions-with-javascript/typing-functions.ts"},{"path":"/zh/play/javascript/helping-with-javascript/errors.ts"},{"path":"/zh/play/javascript/helping-with-javascript/quick-fixes.ts"},{"path":"/zh/play/javascript/javascript-essentials/code-flow.ts"},{"path":"/zh/play/javascript/javascript-essentials/functions.ts"},{"path":"/zh/play/javascript/javascript-essentials/hello-world.ts"},{"path":"/zh/play/javascript/javascript-essentials/objects-and-arrays.ts"},{"path":"/zh/play/javascript/modern-javascript/async-await.ts"},{"path":"/zh/play/javascript/modern-javascript/immutability.ts"},{"path":"/zh/play/javascript/modern-javascript/import-export.ts"},{"path":"/zh/play/javascript/modern-javascript/jsdoc-support.js"},{"path":"/zh/play/javascript/working-with-classes/classes-101.ts"},{"path":"/zh/play/javascript/working-with-classes/generic-classes.ts"},{"path":"/zh/play/javascript/working-with-classes/mixins.ts"},{"path":"/zh/play/javascript/working-with-classes/this.ts"},{"path":"/zh/play/playground/config/javascript-playgrounds.js"},{"path":"/zh/play/playground/config/new-compiler-defaults.ts"},{"path":"/zh/play/playground/language/automatic-type-acquisition.ts"},{"path":"/zh/play/playground/language/fixits.ts"},{"path":"/zh/play/playground/tooling/mobile-support.ts"},{"path":"/zh/play/playground/tooling/sharable-urls.ts"},{"path":"/zh/play/playground/tooling/typescript-versions.ts"},{"path":"/zh/play/typescript/language/soundness.ts"},{"path":"/zh/play/typescript/language/structural-typing.ts"},{"path":"/zh/play/typescript/language/type-guards.ts"},{"path":"/zh/play/typescript/language/type-widening-and-narrowing.ts"},{"path":"/zh/play/typescript/language-extensions/enums.ts"},{"path":"/zh/play/typescript/language-extensions/nominal-typing.ts"},{"path":"/zh/play/typescript/language-extensions/types-vs-interfaces.ts"},{"path":"/zh/play/typescript/meta-types/conditional-types.ts"},{"path":"/zh/play/typescript/meta-types/discriminate-types.ts"},{"path":"/zh/play/typescript/meta-types/indexed-types.ts"},{"path":"/zh/play/typescript/meta-types/mapped-types.ts"},{"path":"/zh/play/typescript/primitives/any.ts"},{"path":"/zh/play/typescript/primitives/literals.ts"},{"path":"/zh/play/typescript/primitives/union-and-intersection-types.ts"},{"path":"/zh/play/typescript/primitives/unknown-and-never.ts"},{"path":"/zh/play/typescript/type-primitives/built-in-utility-types.ts"},{"path":"/zh/play/typescript/type-primitives/nullable-types.ts"},{"path":"/zh/play/typescript/type-primitives/tuples.ts"},{"path":"/ja/play/3-7/syntax-and-messaging/flattened-error-reporting.ts"},{"path":"/ja/play/3-7/fixits/infer-from-usage-changes.ts"},{"path":"/ja/play/3-7/fixits/const-to-let.ts"},{"path":"/community"},{"path":"/es/community"},{"path":"/ja/community"},{"path":"/vo/community"},{"path":"/zh/community"},{"path":"/download"},{"path":"/es/download"},{"path":"/ja/download"},{"path":"/vo/download"},{"path":"/zh/download"},{"path":"/empty"},{"path":"/es/empty"},{"path":"/ja/empty"},{"path":"/vo/empty"},{"path":"/zh/empty"},{"path":"/"},{"path":"/es/"},{"path":"/ja/"},{"path":"/vo/"},{"path":"/zh/"},{"path":"/tools"},{"path":"/es/tools"},{"path":"/ja/tools"},{"path":"/vo/tools"},{"path":"/zh/tools"},{"path":"/why-create-typescript"},{"path":"/es/why-create-typescript"},{"path":"/ja/why-create-typescript"},{"path":"/vo/why-create-typescript"},{"path":"/zh/why-create-typescript"},{"path":"/docs/bootstrap"},{"path":"/es/docs/bootstrap"},{"path":"/ja/docs/bootstrap"},{"path":"/vo/docs/bootstrap"},{"path":"/zh/docs/bootstrap"},{"path":"/docs/"},{"path":"/es/docs/"},{"path":"/ja/docs/"},{"path":"/vo/docs/"},{"path":"/zh/docs/"},{"path":"/docs/handbook/"},{"path":"/es/docs/handbook/"},{"path":"/ja/docs/handbook/"},{"path":"/vo/docs/handbook/"},{"path":"/zh/docs/handbook/"},{"path":"/branding/"},{"path":"/dev/bug-workbench/"},{"path":"/dev/playground-plugins/"},{"path":"/dev/sandbox/"},{"path":"/dev/twoslash/"},{"path":"/dev/typescript-vfs/"},{"path":"/upcoming/"}]},"markdownRemark":{"id":"154f3044-4c20-51c6-ab8d-53e69fef43e1","excerpt":"For programs to be useful, we need to be able to work with some of the simplest units of data: numbers, strings, structures, boolean values, and the like.\nIn…","html":"<p>For programs to be useful, we need to be able to work with some of the simplest units of data: numbers, strings, structures, boolean values, and the like.\nIn TypeScript, we support the same types as you would expect in JavaScript, with an extra enumeration type thrown in to help things along.</p>\n<h2 id=\"boolean\" style=\"position:relative;\"><a href=\"#boolean\" aria-label=\"boolean permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Boolean</h2>\n<p>The most basic datatype is the simple true/false value, which JavaScript and TypeScript call a <code>boolean</code> value.</p>\n<pre class=\"shiki twoslash\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> </span><span style=\"color: #1A1A1A\"><data-lsp lsp='let isDone: boolean'>isDone</data-lsp></span><span style=\"color: #000000\">:</span><span style=\"color: #1A1A1A\"> boolean </span><span style=\"color: #000000\">= </span><span style=\"color: #0000FF\">false</span><span style=\"color: #000000\">;</span></code><a href='https://www.typescriptlang.org/play/#code/DYUwLgBAlgzgIgewHYgFwQEYIaAhkiAXggDNdgYQBuIA'>Try</a></div></pre>\n<h2 id=\"number\" style=\"position:relative;\"><a href=\"#number\" aria-label=\"number permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Number</h2>\n<p>As in JavaScript, all numbers in TypeScript are either floating point values or BigIntegers.\nThese floating point numbers get the type <code>number</code>, while BigIntegers get the type <code>bigint</code>.\nIn addition to hexadecimal and decimal literals, TypeScript also supports binary and octal literals introduced in ECMAScript 2015.</p>\n<pre class=\"shiki twoslash\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> </span><span style=\"color: #1A1A1A\"><data-lsp lsp='let decimal: number'>decimal</data-lsp></span><span style=\"color: #000000\">:</span><span style=\"color: #1A1A1A\"> number </span><span style=\"color: #000000\">= </span><span style=\"color: #09835A\">6</span><span style=\"color: #000000\">;</span>\n<span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> </span><span style=\"color: #1A1A1A\"><data-lsp lsp='let hex: number'>hex</data-lsp></span><span style=\"color: #000000\">:</span><span style=\"color: #1A1A1A\"> number </span><span style=\"color: #000000\">= </span><span style=\"color: #09835A\">0xf00d</span><span style=\"color: #000000\">;</span>\n<span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> </span><span style=\"color: #1A1A1A\"><data-lsp lsp='let binary: number'>binary</data-lsp></span><span style=\"color: #000000\">:</span><span style=\"color: #1A1A1A\"> number </span><span style=\"color: #000000\">= </span><span style=\"color: #09835A\">0b1010</span><span style=\"color: #000000\">;</span>\n<span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> </span><span style=\"color: #1A1A1A\"><data-lsp lsp='let octal: number'>octal</data-lsp></span><span style=\"color: #000000\">:</span><span style=\"color: #1A1A1A\"> number </span><span style=\"color: #000000\">= </span><span style=\"color: #09835A\">0o744</span><span style=\"color: #000000\">;</span>\n<span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> </span><span style=\"color: #1A1A1A\"><data-lsp lsp='let big: bigint'>big</data-lsp></span><span style=\"color: #000000\">:</span><span style=\"color: #1A1A1A\"> bigint </span><span style=\"color: #000000\">= 100</span><span style=\"color: #1A1A1A\">n</span><span style=\"color: #000000\">;</span></code><a href='https://www.typescriptlang.org/play/#code/PTAEAEBcEMCcHMCmkBcoCiBlATABjwFAA2yoAJogMYCWAttEWgHYCutARorKALygBsAbmKkAFogAezNp259cEgGa5cZYSUih21JnACe0jl16hc7AIy5L60gHtKMRqFZG5p2wHYALF5ubt8GgBOpp8lrhMgkA'>Try</a></div></pre>\n<h2 id=\"string\" style=\"position:relative;\"><a href=\"#string\" aria-label=\"string permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>String</h2>\n<p>Another fundamental part of creating programs in JavaScript for webpages and servers alike is working with textual data.\nAs in other languages, we use the type <code>string</code> to refer to these textual datatypes.\nJust like JavaScript, TypeScript also uses double quotes (<code>\"</code>) or single quotes (<code>'</code>) to surround string data.</p>\n<pre class=\"shiki twoslash\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> </span><span style=\"color: #1A1A1A\"><data-lsp lsp='let color: string'>color</data-lsp></span><span style=\"color: #000000\">:</span><span style=\"color: #1A1A1A\"> string </span><span style=\"color: #000000\">= </span><span style=\"color: #A31515\">\"blue\"</span><span style=\"color: #000000\">;</span>\n<span style=\"color: #1A1A1A\"><data-lsp lsp='let color: string'>color</data-lsp></span><span style=\"color: #000000\"> = </span><span style=\"color: #A31515\">\"red\"</span><span style=\"color: #000000\">;</span></code><a href='https://www.typescriptlang.org/play/#code/DYUwLgBAxg9sMCcBcEDOYEEsB2BzCAvBAEQBGwAriMQNwBQs8ChJCIAJrUA'>Try</a></div></pre>\n<p>You can also use <em>template strings</em>, which can span multiple lines and have embedded expressions.\nThese strings are surrounded by the backtick/backquote (<code>`</code>) character, and embedded expressions are of the form <code>${ expr }</code>.</p>\n<pre class=\"shiki twoslash\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> </span><span style=\"color: #1A1A1A\"><data-lsp lsp='let fullName: string'>fullName</data-lsp></span><span style=\"color: #000000\">:</span><span style=\"color: #1A1A1A\"> string </span><span style=\"color: #000000\">= </span><span style=\"color: #A31515\">`Bob Bobbington`</span><span style=\"color: #000000\">;</span>\n<span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> </span><span style=\"color: #1A1A1A\"><data-lsp lsp='let age: number'>age</data-lsp></span><span style=\"color: #000000\">:</span><span style=\"color: #1A1A1A\"> number </span><span style=\"color: #000000\">= </span><span style=\"color: #09835A\">37</span><span style=\"color: #000000\">;</span>\n<span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> </span><span style=\"color: #1A1A1A\"><data-lsp lsp='let sentence: string'>sentence</data-lsp></span><span style=\"color: #000000\">:</span><span style=\"color: #1A1A1A\"> string </span><span style=\"color: #000000\">= </span><span style=\"color: #A31515\">`Hello, my name is </span><span style=\"color: #0000FF\">${</span><span style=\"color: #1A1A1A\"><data-lsp lsp='let fullName: string'>fullName</data-lsp></span><span style=\"color: #0000FF\">}</span><span style=\"color: #A31515\">.</span>\n\n<span style=\"color: #A31515\">I&apos;ll be </span><span style=\"color: #0000FF\">${</span><span style=\"color: #1A1A1A\"><data-lsp lsp='let age: number'>age</data-lsp></span><span style=\"color: #A31515\"> </span><span style=\"color: #000000\">+</span><span style=\"color: #A31515\"> </span><span style=\"color: #09835A\">1</span><span style=\"color: #0000FF\">}</span><span style=\"color: #A31515\"> years old next month.`</span><span style=\"color: #000000\">;</span></code><a href='https://www.typescriptlang.org/play/#code/DYUwLgBAZgrswDkCGBbEAuCBnMAnAlgHYDmEAvBAAYBCA9gEYR331HFi2GUDcAUKJCTEMEQjBT0QuchADMAdj4DsIQmFUBjETgIkZlABIh4tADQQUAT1GoQEfFggASAN6x4yNAF8AdL14AkgDk8BCSzi5CdgDUEACMXhCWIEi4jrTAACaiIAAekCicYAAWPjxAA'>Try</a></div></pre>\n<p>This is equivalent to declaring <code>sentence</code> like so:</p>\n<pre class=\"shiki twoslash\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> </span><span style=\"color: #1A1A1A\"><data-lsp lsp='let sentence: string'>sentence</data-lsp></span><span style=\"color: #000000\">:</span><span style=\"color: #1A1A1A\"> string </span><span style=\"color: #000000\">=</span>\n<span style=\"color: #000000\">  </span><span style=\"color: #A31515\">\"Hello, my name is \"</span><span style=\"color: #000000\"> +</span>\n<span style=\"color: #000000\">  </span><span style=\"color: #1A1A1A\"><data-lsp lsp='let fullName: string'>fullName</data-lsp></span><span style=\"color: #000000\"> +</span>\n<span style=\"color: #000000\">  </span><span style=\"color: #A31515\">\".\\n\\n\"</span><span style=\"color: #000000\"> +</span>\n<span style=\"color: #000000\">  </span><span style=\"color: #A31515\">\"I&apos;ll be \"</span><span style=\"color: #000000\"> +</span>\n<span style=\"color: #000000\">  (</span><span style=\"color: #1A1A1A\"><data-lsp lsp='let age: number'>age</data-lsp></span><span style=\"color: #000000\"> + </span><span style=\"color: #09835A\">1</span><span style=\"color: #000000\">) +</span>\n<span style=\"color: #000000\">  </span><span style=\"color: #A31515\">\" years old next month.\"</span><span style=\"color: #000000\">;</span></code><a href='https://www.typescriptlang.org/play/#code/DYUwLgBAZgrswDkCGBbEAuCBnMAnAlgHYDmEAvBAAYBCA9gEYR331HFi2GUDcAUKJCTEMEQjBT0QuchADMAdj4B6JRAC0GgMYwwGtf3DYQhMMc0icBEuV4QIAIgASIeLQA0EFAE9RqEBHwsBwgAaltoOEQ-UPD7ADoAHUIk+xi7ewBJAHJ4CElgsLsACiF-EIgARgBKNOCvECRcINpgABNREAAPSBROMAALOPtuIA'>Try</a></div></pre>\n<h2 id=\"array\" style=\"position:relative;\"><a href=\"#array\" aria-label=\"array permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Array</h2>\n<p>TypeScript, like JavaScript, allows you to work with arrays of values.\nArray types can be written in one of two ways.\nIn the first, you use the type of the elements followed by <code>[]</code> to denote an array of that element type:</p>\n<pre class=\"shiki twoslash\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> </span><span style=\"color: #1A1A1A\"><data-lsp lsp='let list: number[]'>list</data-lsp></span><span style=\"color: #000000\">:</span><span style=\"color: #1A1A1A\"> number[] </span><span style=\"color: #000000\">= [</span><span style=\"color: #09835A\">1</span><span style=\"color: #000000\">, </span><span style=\"color: #09835A\">2</span><span style=\"color: #000000\">, </span><span style=\"color: #09835A\">3</span><span style=\"color: #000000\">];</span></code><a href='https://www.typescriptlang.org/play/#code/DYUwLgBMCWDOYC4IDsCuBbARiATgbQF0IBeCPARgBoIAmagZgIG4g'>Try</a></div></pre>\n<p>The second way uses a generic array type, <code>Array&#x3C;elemType></code>:</p>\n<pre class=\"shiki twoslash\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> </span><span style=\"color: #1A1A1A\"><data-lsp lsp='let list: number[]'>list</data-lsp></span><span style=\"color: #000000\">:</span><span style=\"color: #1A1A1A\"> <data-lsp lsp='interface Array&amp;lt;T>'>Array</data-lsp>&lt;number> </span><span style=\"color: #000000\">= [</span><span style=\"color: #09835A\">1</span><span style=\"color: #000000\">, </span><span style=\"color: #09835A\">2</span><span style=\"color: #000000\">, </span><span style=\"color: #09835A\">3</span><span style=\"color: #000000\">];</span></code><a href='https://www.typescriptlang.org/play/#code/DYUwLgBMCWDOYC4IEEBOqCGBPAPAOwFcBbAIxFQD4IBeCAbQEYAaCAJhYGYBdAbiA'>Try</a></div></pre>\n<h2 id=\"tuple\" style=\"position:relative;\"><a href=\"#tuple\" aria-label=\"tuple permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Tuple</h2>\n<p>Tuple types allow you to express an array with a fixed number of elements whose types are known, but need not be the same. For example, you may want to represent a value as a pair of a <code>string</code> and a <code>number</code>:</p>\n<pre class=\"shiki twoslash\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #008000\">// Declare a tuple type</span>\n<span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> </span><span style=\"color: #1A1A1A\"><data-lsp lsp='let x: [string, number]'>x</data-lsp></span><span style=\"color: #000000\">:</span><span style=\"color: #1A1A1A\"> [string, number]</span><span style=\"color: #000000\">;</span>\n<span style=\"color: #008000\">// Initialize it</span>\n<span style=\"color: #1A1A1A\"><data-lsp lsp='let x: [string, number]'>x</data-lsp></span><span style=\"color: #000000\"> = [</span><span style=\"color: #A31515\">\"hello\"</span><span style=\"color: #000000\">, </span><span style=\"color: #09835A\">10</span><span style=\"color: #000000\">]; </span><span style=\"color: #008000\">// OK</span>\n<span style=\"color: #008000\">// Initialize it incorrectly</span>\n<span style=\"color: #1A1A1A\"><data-lsp lsp='let x: [string, number]'>x</data-lsp></span><span style=\"color: #000000\"> = [</span><span style=\"color: #09835A\"><data-err>10</data-err></span><span style=\"color: #000000\">, </span><span style=\"color: #A31515\"><data-err>&quot;hello&quot;</data-err></span><span style=\"color: #000000\">]; </span><span style=\"color: #008000\">// Error</span>\n<span class=\"error\"><span>Type 'number' is not assignable to type 'string'.</br>Type 'string' is not assignable to type 'number'.</span><span class=\"code\">2322<br/>2322</span></span><span class=\"error-behind\">Type 'number' is not assignable to type 'string'.</br>Type 'string' is not assignable to type 'number'.</span></code><a href='https://www.typescriptlang.org/play/#code/PTAEAEFMCdoe2gZwFygEwGY1oFAlACKQDGANgIbSSjmgAuArgA6nV0CeTkOrdoAHqgDaiOtACWAOwDmAGlCSGAWwBGMALoBuPGACSk8XXHlS4gF7VDOfqAC8oIQCIAFpFKk4j+QEYADFtB8AHkAaR1QfUNjUwtQQzjJYgQqYjpSdms7Bz95FzcPRwD8AFFYBCA'>Try</a></div></pre>\n<p>When accessing an element with a known index, the correct type is retrieved:</p>\n<pre class=\"shiki twoslash\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #008000\">// OK</span>\n<span style=\"color: #000000\"><data-lsp lsp='var console: Console'>console</data-lsp>.<data-lsp lsp='(method) Console.log(...data: any[]): void'>log</data-lsp>(</span><span style=\"color: #1A1A1A\"><data-lsp lsp='let x: [string, number]'>x</data-lsp></span><span style=\"color: #000000\">[</span><span style=\"color: #09835A\">0</span><span style=\"color: #000000\">].<data-lsp lsp='(method) String.substring(start: number, end?: number | undefined): string'>substring</data-lsp>(</span><span style=\"color: #09835A\">1</span><span style=\"color: #000000\">));</span>\n\n<span style=\"color: #000000\"><data-lsp lsp='var console: Console'>console</data-lsp>.<data-lsp lsp='(method) Console.log(...data: any[]): void'>log</data-lsp>(</span><span style=\"color: #1A1A1A\"><data-lsp lsp='let x: [string, number]'>x</data-lsp></span><span style=\"color: #000000\">[</span><span style=\"color: #09835A\">1</span><span style=\"color: #000000\"><data-err>].<data-lsp lsp='any'>substring</data-lsp>(</data-err></span><span style=\"color: #09835A\">1</span><span style=\"color: #000000\">));</span>\n<span class=\"error\"><span>Property 'substring' does not exist on type 'number'.</span><span class=\"code\">2339</span></span><span class=\"error-behind\">Property 'substring' does not exist on type 'number'.</span></code><a href='https://www.typescriptlang.org/play/#code/PTAEAEFMCdoe2gZwFygEwGYME4BQAbSAF1AA9UBtRI6ASwDsBzAGlHoFcBbAIxgF0A3LlKgAvKAoAiABaR8+OJNYBGAAyDQIUAHkA0rhBgAtCYDG7IiaMGwe3Kbj1EcQgDoFjABSkK614nZuajomT2UASnChe0dnNw9vCmU+f0Dghi8IqKA'>Try</a></div></pre>\n<p>Accessing an element outside the set of known indices fails with an error:</p>\n<pre class=\"shiki twoslash\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #1A1A1A\"><data-lsp lsp='let x: [string, number]'>x</data-lsp></span><span style=\"color: #000000\">[</span><span style=\"color: #09835A\"><data-err>3</data-err></span><span style=\"color: #000000\">] = </span><span style=\"color: #A31515\">\"world\"</span><span style=\"color: #000000\">;</span>\n<span class=\"error\"><span>Tuple type '[string, number]' of length '2' has no element at index '3'.</span><span class=\"code\">2493</span></span><span class=\"error-behind\">Tuple type '[string, number]' of length '2' has no element at index '3'.</span>\n<span style=\"color: #000000\"><data-lsp lsp='var console: Console'>console</data-lsp>.<data-lsp lsp='(method) Console.log(...data: any[]): void'>log</data-lsp>(</span><span style=\"color: #1A1A1A\"><data-lsp lsp='let x: [string, number]'>x</data-lsp></span><span style=\"color: #000000\">[</span><span style=\"color: #09835A\"><data-err>5</data-err></span><span style=\"color: #000000\">].<data-lsp lsp='any'>toString</data-lsp>());</span>\n<span class=\"error\"><span>Object is possibly 'undefined'.</br>Tuple type '[string, number]' of length '2' has no element at index '5'.</span><span class=\"code\">2532<br/>2493</span></span><span class=\"error-behind\">Object is possibly 'undefined'.</br>Tuple type '[string, number]' of length '2' has no element at index '5'.</span></code><a href='https://www.typescriptlang.org/play/#code/PTAEAEFMCdoe2gZwFygEwBYCcBmdBWHNdItAKABtIAXUAD1QG1FroBLAOwHMAaUDgK4BbAEYwAugG4ydUAF5QjAEQALSBQpwlfAIwAGKaBCgA8gGkyIMAFpbAYwHVb1mYxzj5oJQHcEFACZK0mR2cByIcFQAdJpcABR0jPjiUdRwAMqsnPEAlDmSQA'>Try</a></div></pre>\n<h2 id=\"enum\" style=\"position:relative;\"><a href=\"#enum\" aria-label=\"enum permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Enum</h2>\n<p>A helpful addition to the standard set of datatypes from JavaScript is the <code>enum</code>.\nAs in languages like C#, an enum is a way of giving more friendly names to sets of numeric values.</p>\n<pre class=\"shiki twoslash\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">enum</span><span style=\"color: #000000\"> <data-lsp lsp='enum Color'>Color</data-lsp> {</span>\n<span style=\"color: #000000\">  </span><span style=\"color: #1A1A1A\"><data-lsp lsp='(enum member) Color.Red = 0'>Red</data-lsp></span><span style=\"color: #000000\">,</span>\n<span style=\"color: #000000\">  </span><span style=\"color: #1A1A1A\"><data-lsp lsp='(enum member) Color.Green = 1'>Green</data-lsp></span><span style=\"color: #000000\">,</span>\n<span style=\"color: #000000\">  </span><span style=\"color: #1A1A1A\"><data-lsp lsp='(enum member) Color.Blue = 2'>Blue</data-lsp></span><span style=\"color: #000000\">,</span>\n<span style=\"color: #000000\">}</span>\n<span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> </span><span style=\"color: #1A1A1A\"><data-lsp lsp='let c: Color'>c</data-lsp></span><span style=\"color: #000000\">:</span><span style=\"color: #1A1A1A\"> <data-lsp lsp='enum Color'>Color</data-lsp> </span><span style=\"color: #000000\">= </span><span style=\"color: #1A1A1A\"><data-lsp lsp='enum Color'>Color</data-lsp></span><span style=\"color: #000000\">.</span><span style=\"color: #1A1A1A\"><data-lsp lsp='(enum member) Color.Green = 1'>Green</data-lsp></span><span style=\"color: #000000\">;</span></code><a href='https://www.typescriptlang.org/play/#code/KYOwrgtgBAwg9gGzgJygbwFBSgJWAEwBosoBxZYUY7AIQTGGIF8MFgAXKAYwC5ZEUUALz8kyAHTlKIANxA'>Try</a></div></pre>\n<p>By default, enums begin numbering their members starting at <code>0</code>.\nYou can change this by manually setting the value of one of its members.\nFor example, we can start the previous example at <code>1</code> instead of <code>0</code>:</p>\n<pre class=\"shiki twoslash\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">enum</span><span style=\"color: #000000\"> <data-lsp lsp='enum Color'>Color</data-lsp> {</span>\n<span style=\"color: #000000\">  </span><span style=\"color: #1A1A1A\"><data-lsp lsp='(enum member) Color.Red = 1'>Red</data-lsp></span><span style=\"color: #000000\"> = </span><span style=\"color: #09835A\">1</span><span style=\"color: #000000\">,</span>\n<span style=\"color: #000000\">  </span><span style=\"color: #1A1A1A\"><data-lsp lsp='(enum member) Color.Green = 2'>Green</data-lsp></span><span style=\"color: #000000\">,</span>\n<span style=\"color: #000000\">  </span><span style=\"color: #1A1A1A\"><data-lsp lsp='(enum member) Color.Blue = 3'>Blue</data-lsp></span><span style=\"color: #000000\">,</span>\n<span style=\"color: #000000\">}</span>\n<span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> </span><span style=\"color: #1A1A1A\"><data-lsp lsp='let c: Color'>c</data-lsp></span><span style=\"color: #000000\">:</span><span style=\"color: #1A1A1A\"> <data-lsp lsp='enum Color'>Color</data-lsp> </span><span style=\"color: #000000\">= </span><span style=\"color: #1A1A1A\"><data-lsp lsp='enum Color'>Color</data-lsp></span><span style=\"color: #000000\">.</span><span style=\"color: #1A1A1A\"><data-lsp lsp='(enum member) Color.Green = 2'>Green</data-lsp></span><span style=\"color: #000000\">;</span></code><a href='https://www.typescriptlang.org/play/#code/KYOwrgtgBAwg9gGzgJygbwFBSgJWAEygF4oBGAGiygHFlhRLsAhBMYSgXwwWABcoAxgC5YiFMVFJkAOlr0QAbiA'>Try</a></div></pre>\n<p>Or, even manually set all the values in the enum:</p>\n<pre class=\"shiki twoslash\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">enum</span><span style=\"color: #000000\"> <data-lsp lsp='enum Color'>Color</data-lsp> {</span>\n<span style=\"color: #000000\">  </span><span style=\"color: #1A1A1A\"><data-lsp lsp='(enum member) Color.Red = 1'>Red</data-lsp></span><span style=\"color: #000000\"> = </span><span style=\"color: #09835A\">1</span><span style=\"color: #000000\">,</span>\n<span style=\"color: #000000\">  </span><span style=\"color: #1A1A1A\"><data-lsp lsp='(enum member) Color.Green = 2'>Green</data-lsp></span><span style=\"color: #000000\"> = </span><span style=\"color: #09835A\">2</span><span style=\"color: #000000\">,</span>\n<span style=\"color: #000000\">  </span><span style=\"color: #1A1A1A\"><data-lsp lsp='(enum member) Color.Blue = 4'>Blue</data-lsp></span><span style=\"color: #000000\"> = </span><span style=\"color: #09835A\">4</span><span style=\"color: #000000\">,</span>\n<span style=\"color: #000000\">}</span>\n<span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> </span><span style=\"color: #1A1A1A\"><data-lsp lsp='let c: Color'>c</data-lsp></span><span style=\"color: #000000\">:</span><span style=\"color: #1A1A1A\"> <data-lsp lsp='enum Color'>Color</data-lsp> </span><span style=\"color: #000000\">= </span><span style=\"color: #1A1A1A\"><data-lsp lsp='enum Color'>Color</data-lsp></span><span style=\"color: #000000\">.</span><span style=\"color: #1A1A1A\"><data-lsp lsp='(enum member) Color.Green = 2'>Green</data-lsp></span><span style=\"color: #000000\">;</span></code><a href='https://www.typescriptlang.org/play/#code/KYOwrgtgBAwg9gGzgJygbwFBSgJWAEygF4oBGAGiygHFlhRioAmS7AIQTGEYBZKBfDAmAAXKAGMAXLEQpG8JMgB0teiADcQA'>Try</a></div></pre>\n<p>A handy feature of enums is that you can also go from a numeric value to the name of that value in the enum.\nFor example, if we had the value <code>2</code> but weren’t sure what that mapped to in the <code>Color</code> enum above, we could look up the corresponding name:</p>\n<pre class=\"shiki twoslash\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">enum</span><span style=\"color: #000000\"> <data-lsp lsp='enum Color'>Color</data-lsp> {</span>\n<span style=\"color: #000000\">  </span><span style=\"color: #1A1A1A\"><data-lsp lsp='(enum member) Color.Red = 1'>Red</data-lsp></span><span style=\"color: #000000\"> = </span><span style=\"color: #09835A\">1</span><span style=\"color: #000000\">,</span>\n<span style=\"color: #000000\">  </span><span style=\"color: #1A1A1A\"><data-lsp lsp='(enum member) Color.Green = 2'>Green</data-lsp></span><span style=\"color: #000000\">,</span>\n<span style=\"color: #000000\">  </span><span style=\"color: #1A1A1A\"><data-lsp lsp='(enum member) Color.Blue = 3'>Blue</data-lsp></span><span style=\"color: #000000\">,</span>\n<span style=\"color: #000000\">}</span>\n<span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> </span><span style=\"color: #1A1A1A\"><data-lsp lsp='let colorName: string'>colorName</data-lsp></span><span style=\"color: #000000\">:</span><span style=\"color: #1A1A1A\"> string </span><span style=\"color: #000000\">= </span><span style=\"color: #1A1A1A\"><data-lsp lsp='enum Color'>Color</data-lsp></span><span style=\"color: #000000\">[</span><span style=\"color: #09835A\">2</span><span style=\"color: #000000\">];</span>\n\n<span style=\"color: #008000\">// Displays &apos;Green&apos;</span>\n<span style=\"color: #000000\"><data-lsp lsp='var console: Console'>console</data-lsp>.<data-lsp lsp='(method) Console.log(...data: any[]): void'>log</data-lsp>(</span><span style=\"color: #1A1A1A\"><data-lsp lsp='let colorName: string'>colorName</data-lsp></span><span style=\"color: #000000\">);</span></code><a href='https://www.typescriptlang.org/play/#code/KYOwrgtgBAwg9gGzgJygbwFBSgJWAEygF4oBGAGiygHFlhRLsAhBMYSgXwwWABcoAxohQA5AIYRgALigBnXsgCWIAObFYw5AG0ATAF0A3BgwB6E1AAii2QAcEYgJ6yoAclr0QLjEJCzEwADokFQAKISRkcUkASgMgA'>Try</a></div></pre>\n<h2 id=\"unknown\" style=\"position:relative;\"><a href=\"#unknown\" aria-label=\"unknown permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Unknown</h2>\n<p>We may need to describe the type of variables that we do not know when we are writing an application.\nThese values may come from dynamic content – e.g. from the user – or we may want to intentionally accept all values in our API.\nIn these cases, we want to provide a type that tells the compiler and future readers that this variable could be anything, so we give it the <code>unknown</code> type.</p>\n<pre class=\"shiki twoslash\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> </span><span style=\"color: #1A1A1A\"><data-lsp lsp='let notSure: unknown'>notSure</data-lsp></span><span style=\"color: #000000\">:</span><span style=\"color: #1A1A1A\"> unknown </span><span style=\"color: #000000\">= </span><span style=\"color: #09835A\">4</span><span style=\"color: #000000\">;</span>\n<span style=\"color: #1A1A1A\"><data-lsp lsp='let notSure: unknown'>notSure</data-lsp></span><span style=\"color: #000000\"> = </span><span style=\"color: #A31515\">\"maybe a string instead\"</span><span style=\"color: #000000\">;</span>\n\n<span style=\"color: #008000\">// OK, definitely a boolean</span>\n<span style=\"color: #1A1A1A\"><data-lsp lsp='let notSure: unknown'>notSure</data-lsp></span><span style=\"color: #000000\"> = </span><span style=\"color: #0000FF\">false</span><span style=\"color: #000000\">;</span></code><a href='https://www.typescriptlang.org/play/#code/DYUwLgBAdg9mDKBXATiAXBRUDWsDuUEAvBACwDcAULAiiMRAEQC2AhgJ4BG9rEAzmGQBLKAHMIIgSFYATRlUoB6RRADyAaQA0EGSABmIoWBDB2EXpxgxQrKNThJUDPa2B8Q5IA'>Try</a></div></pre>\n<p>If you have a variable with an unknown type, you can narrow it to something more specific by doing <code>typeof</code> checks, comparison checks, or more advanced type guards that will be discussed in a later chapter:</p>\n<pre class=\"shiki twoslash\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">declare</span><span style=\"color: #000000\"> </span><span style=\"color: #0000FF\">const</span><span style=\"color: #000000\"> </span><span style=\"color: #1A1A1A\"><data-lsp lsp='const maybe: unknown'>maybe</data-lsp></span><span style=\"color: #000000\">:</span><span style=\"color: #1A1A1A\"> unknown</span><span style=\"color: #000000\">;</span>\n<span style=\"color: #008000\">// &apos;maybe&apos; could be a string, object, boolean, undefined, or other types</span>\n<span style=\"color: #0000FF\">const</span><span style=\"color: #000000\"> </span><span style=\"color: #1A1A1A\"><data-err><data-lsp lsp='const aNumber: number'>aNumber</data-lsp></data-err></span><span style=\"color: #000000\">:</span><span style=\"color: #1A1A1A\"> number </span><span style=\"color: #000000\">= </span><span style=\"color: #1A1A1A\"><data-lsp lsp='const maybe: unknown'>maybe</data-lsp></span><span style=\"color: #000000\">;</span>\n<span class=\"error\"><span>Type 'unknown' is not assignable to type 'number'.</span><span class=\"code\">2322</span></span><span class=\"error-behind\">Type 'unknown' is not assignable to type 'number'.</span>\n<span style=\"color: #0000FF\">if</span><span style=\"color: #000000\"> (</span><span style=\"color: #1A1A1A\"><data-lsp lsp='const maybe: unknown'>maybe</data-lsp></span><span style=\"color: #000000\"> === </span><span style=\"color: #0000FF\">true</span><span style=\"color: #000000\">) {</span>\n<span style=\"color: #000000\">  </span><span style=\"color: #008000\">// TypeScript knows that maybe is a boolean now</span>\n<span style=\"color: #000000\">  </span><span style=\"color: #0000FF\">const</span><span style=\"color: #000000\"> </span><span style=\"color: #1A1A1A\"><data-lsp lsp='const aBoolean: boolean'>aBoolean</data-lsp></span><span style=\"color: #000000\">:</span><span style=\"color: #1A1A1A\"> boolean </span><span style=\"color: #000000\">= </span><span style=\"color: #1A1A1A\"><data-lsp lsp='const maybe: true'>maybe</data-lsp></span><span style=\"color: #000000\">;</span>\n<span style=\"color: #000000\">  </span><span style=\"color: #008000\">// So, it cannot be a string</span>\n<span style=\"color: #000000\">  </span><span style=\"color: #0000FF\">const</span><span style=\"color: #000000\"> </span><span style=\"color: #1A1A1A\"><data-err><data-lsp lsp='const aString: string'>aString</data-lsp></data-err></span><span style=\"color: #000000\">:</span><span style=\"color: #1A1A1A\"> string </span><span style=\"color: #000000\">= </span><span style=\"color: #1A1A1A\"><data-lsp lsp='const maybe: true'>maybe</data-lsp></span><span style=\"color: #000000\">;</span>\n<span class=\"error\"><span>Type 'boolean' is not assignable to type 'string'.</span><span class=\"code\">2322</span></span><span class=\"error-behind\">Type 'boolean' is not assignable to type 'string'.</span><span style=\"color: #000000\">}</span>\n\n<span style=\"color: #0000FF\">if</span><span style=\"color: #000000\"> (</span><span style=\"color: #0000FF\">typeof</span><span style=\"color: #000000\"> </span><span style=\"color: #1A1A1A\"><data-lsp lsp='const maybe: unknown'>maybe</data-lsp></span><span style=\"color: #000000\"> === </span><span style=\"color: #A31515\">\"string\"</span><span style=\"color: #000000\">) {</span>\n<span style=\"color: #000000\">  </span><span style=\"color: #008000\">// TypeScript knows that maybe is a string</span>\n<span style=\"color: #000000\">  </span><span style=\"color: #0000FF\">const</span><span style=\"color: #000000\"> </span><span style=\"color: #1A1A1A\"><data-lsp lsp='const aString: string'>aString</data-lsp></span><span style=\"color: #000000\">:</span><span style=\"color: #1A1A1A\"> string </span><span style=\"color: #000000\">= </span><span style=\"color: #1A1A1A\"><data-lsp lsp='const maybe: string'>maybe</data-lsp></span><span style=\"color: #000000\">;</span>\n<span style=\"color: #000000\">  </span><span style=\"color: #008000\">// So, it cannot be a boolean</span>\n<span style=\"color: #000000\">  </span><span style=\"color: #0000FF\">const</span><span style=\"color: #000000\"> </span><span style=\"color: #1A1A1A\"><data-err><data-lsp lsp='const aBoolean: boolean'>aBoolean</data-lsp></data-err></span><span style=\"color: #000000\">:</span><span style=\"color: #1A1A1A\"> boolean </span><span style=\"color: #000000\">= </span><span style=\"color: #1A1A1A\"><data-lsp lsp='const maybe: string'>maybe</data-lsp></span><span style=\"color: #000000\">;</span>\n<span class=\"error\"><span>Type 'string' is not assignable to type 'boolean'.</span><span class=\"code\">2322</span></span><span class=\"error-behind\">Type 'string' is not assignable to type 'boolean'.</span><span style=\"color: #000000\">}</span></code><a href='https://www.typescriptlang.org/play/#code/PTAEAEFMCdoe2gZwFygEwGY1vVnnsAoAE0gGMAbAQ2klDLgDtEAXUAWyoE8AjSVAK6MA1ozgB3RgG5CIUAHJOvSPPpwBFYqD6gqoVtACWjAOYAaUHB4Arciws84cCpCqMLQ0gDNjkYhYRLFgALGFAWLgAHSERCBmY2KgA5AXY+aFRGVPTQAF4Obj4ZQkMvUAAKJR1cmvDoAUgASlAAb0JQUDkAFSjIAGUyI0i2UQlEcOCqNiq6Q3G9R2dXRlAxcXa1BN0AIScXN1RF-ZX8mZkOuT64C0M2MjcxNh09A2MTDfjWXT6WI1NUV6mPIFZQyAC+hBKZXKEWicDKMzytQARICTMjmm0LmAetEBkMRmtxiEpiCdHNdPpfm8PkwvlQfn8TADqUDToVIOdOmArjc7g84E86As9staVsqLslgdtKK3MCzoQwUA'>Try</a></div></pre>\n<h2 id=\"any\" style=\"position:relative;\"><a href=\"#any\" aria-label=\"any permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Any</h2>\n<p>In some situations, not all type information is available or it’s declaration would take an inappropriate amount of effort.\nThese may occur for values from code that has been written without TypeScript or a 3rd party library.\nIn these cases, we might want to opt-out of type checking.\nTo do so, we label these values with the <code>any</code> type:</p>\n<pre class=\"shiki twoslash\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">declare</span><span style=\"color: #000000\"> </span><span style=\"color: #0000FF\">function</span><span style=\"color: #000000\"> <data-lsp lsp='function getValue(key: string): any'>getValue</data-lsp>(</span><span style=\"color: #1A1A1A\"><data-lsp lsp='(parameter) key: string'>key</data-lsp></span><span style=\"color: #000000\">: string): any;</span>\n<span style=\"color: #008000\">// OK, return value of &apos;getValue&apos; is not checked</span>\n<span style=\"color: #0000FF\">const</span><span style=\"color: #000000\"> </span><span style=\"color: #1A1A1A\"><data-lsp lsp='const str: string'>str</data-lsp></span><span style=\"color: #000000\">:</span><span style=\"color: #1A1A1A\"> string </span><span style=\"color: #000000\">= <data-lsp lsp='function getValue(key: string): any'>getValue</data-lsp>(</span><span style=\"color: #A31515\">\"myString\"</span><span style=\"color: #000000\">);</span></code><a href='https://www.typescriptlang.org/play/#code/CYUwxgNghgTiAEAzArgOzAFwJYHtXwHMQMA1KCZEACgGsQBPALngGcMYtUCBKZqVegG4AUAHpR8APIBpADTw4GZDHwA3cpXg5E8AORFSGkLvhYW8VDgzwwAC3B1gwsHjat2zNhy7wAvIWIyCmoAIgBbegBldk4CEO5BIA'>Try</a></div></pre>\n<p>The <code>any</code> type is a powerful way to work with existing JavaScript, allowing you to gradually opt-in and opt-out of type checking during compilation.</p>\n<p>Unlike <code>unknown</code>, variables of type <code>any</code> allow you to access arbitrary properties, even ones that don’t exist.\nThese properties include functions and TypeScript will not check their existence or type:</p>\n<pre class=\"shiki twoslash\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> </span><span style=\"color: #1A1A1A\"><data-lsp lsp='let looselyTyped: any'>looselyTyped</data-lsp></span><span style=\"color: #000000\">:</span><span style=\"color: #1A1A1A\"> any </span><span style=\"color: #000000\">= </span><span style=\"color: #09835A\">4</span><span style=\"color: #000000\">;</span>\n<span style=\"color: #008000\">// OK, ifItExists might exist at runtime</span>\n<span style=\"color: #1A1A1A\"><data-lsp lsp='let looselyTyped: any'>looselyTyped</data-lsp></span><span style=\"color: #000000\">.<data-lsp lsp='any'>ifItExists</data-lsp>();</span>\n<span style=\"color: #008000\">// OK, toFixed exists (but the compiler doesn&apos;t check)</span>\n<span style=\"color: #1A1A1A\"><data-lsp lsp='let looselyTyped: any'>looselyTyped</data-lsp></span><span style=\"color: #000000\">.<data-lsp lsp='any'>toFixed</data-lsp>();</span>\n\n<span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> </span><span style=\"color: #1A1A1A\"><data-lsp lsp='let strictlyTyped: unknown'>strictlyTyped</data-lsp></span><span style=\"color: #000000\">:</span><span style=\"color: #1A1A1A\"> unknown </span><span style=\"color: #000000\">= </span><span style=\"color: #09835A\">4</span><span style=\"color: #000000\">;</span>\n<span style=\"color: #1A1A1A\"><data-err><data-lsp lsp='let strictlyTyped: unknown'>strictlyTyped</data-lsp></data-err></span><span style=\"color: #000000\">.<data-lsp lsp='any'>toFixed</data-lsp>();</span>\n<span class=\"error\"><span>Object is of type 'unknown'.</span><span class=\"code\">2571</span></span><span class=\"error-behind\">Object is of type 'unknown'.</span></code><a href='https://www.typescriptlang.org/play/#code/PTAEAEFMCdoe2gZwFygEwFYDsBGAUADaQAuoBccikBAngCo0AOkAJqgIYB2NoAvKABYA3HhCgA8gGkANKACWAMwCSxAKIAPOYmKJQAWzkBzABalIm7aHaloAV07E5eyIQpVaDZiwB0ilRq0dAAoAShExKVliOAAxOXVWUHNA3SCAI1tSYmNIUABjOD1GOSJoUBY4SEROAHJSPJy8gGsQ10pqeiZWb2i4hJZQkUISUG1oOTziDy62UHsmzjgAd04+QRExianOrx7Y+NZBoA'>Try</a></div></pre>\n<p>The <code>any</code> will continue to propagate through your objects:</p>\n<pre class=\"shiki twoslash\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> </span><span style=\"color: #1A1A1A\"><data-lsp lsp='let looselyTyped: any'>looselyTyped</data-lsp></span><span style=\"color: #000000\">:</span><span style=\"color: #1A1A1A\"> any </span><span style=\"color: #000000\">= {};</span>\n<span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> </span><span style=\"color: #1A1A1A\"><data-lsp lsp='let d: any'>d</data-lsp> </span><span style=\"color: #000000\">= </span><span style=\"color: #1A1A1A\"><data-lsp lsp='let looselyTyped: any'>looselyTyped</data-lsp></span><span style=\"color: #000000\">.</span><span style=\"color: #1A1A1A\"><data-lsp lsp='any'>a</data-lsp></span><span style=\"color: #000000\">.</span><span style=\"color: #1A1A1A\"><data-lsp lsp='any'>b</data-lsp></span><span style=\"color: #000000\">.</span><span style=\"color: #1A1A1A\"><data-lsp lsp='any'>c</data-lsp></span><span style=\"color: #000000\">.</span><span style=\"color: #1A1A1A\"><data-lsp lsp='any'>d</data-lsp></span><span style=\"color: #000000\">;</span>\n<span class='query'>//  ^ = let d: any</span></code><a href='https://www.typescriptlang.org/play/#code/DYUwLgBMD20M4mATwCpIA4gCYC4IEMA7JCAXggG8BfAbgChRIsypYFk1MsA6fbgI24BjblnoB6cRAgA9APxA'>Try</a></div></pre>\n<p>After all, remember that all the convenience of <code>any</code> comes at the cost of losing type safety.\nType safety is one of the main motivations for using TypeScript and you should try to avoid using <code>any</code> when not necessary.</p>\n<h2 id=\"void\" style=\"position:relative;\"><a href=\"#void\" aria-label=\"void permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Void</h2>\n<p><code>void</code> is a little like the opposite of <code>any</code>: the absence of having any type at all.\nYou may commonly see this as the return type of functions that do not return a value:</p>\n<pre class=\"shiki twoslash\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">function</span><span style=\"color: #000000\"> <data-lsp lsp='function warnUser(): void'>warnUser</data-lsp>(): void {</span>\n<span style=\"color: #000000\">  <data-lsp lsp='var console: Console'>console</data-lsp>.<data-lsp lsp='(method) Console.log(...data: any[]): void'>log</data-lsp>(</span><span style=\"color: #A31515\">\"This is my warning message\"</span><span style=\"color: #000000\">);</span>\n<span style=\"color: #000000\">}</span></code><a href='https://www.typescriptlang.org/play/#code/GYVwdgxgLglg9mABAdwIYCcwFUDOBTdACgEoAuRANzhgBNEBvAKEUQgRzgBs8A6TuAOaEARABUAFjByIpiALYBPFBjAwwA+Xhw5UAvMOIBuRgF8gA'>Try</a></div></pre>\n<p>Declaring variables of type <code>void</code> is not useful because you can only assign <code>null</code> (only if <code>--strictNullChecks</code> is not specified, see next section) or <code>undefined</code> to them:</p>\n<pre class=\"shiki twoslash\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> </span><span style=\"color: #1A1A1A\"><data-lsp lsp='let unusable: void'>unusable</data-lsp></span><span style=\"color: #000000\">:</span><span style=\"color: #1A1A1A\"> void </span><span style=\"color: #000000\">= </span><span style=\"color: #0000FF\"><data-lsp lsp='var undefined'>undefined</data-lsp></span><span style=\"color: #000000\">;</span>\n<span style=\"color: #008000\">// OK if `--strictNullChecks` is not given</span>\n<span style=\"color: #1A1A1A\"><data-lsp lsp='let unusable: void'>unusable</data-lsp></span><span style=\"color: #000000\"> = </span><span style=\"color: #0000FF\">null</span><span style=\"color: #000000\">;</span></code><a href='https://www.typescriptlang.org/play/#code/PTAEAEGcBcCcEsDG0BcoBmBDANpApgFDZ7SgCuAdmZJgEbFoBuA9vACagC85Fbe68CnjYBuAiFAB5ANKh46UAAMAtMpgJkAOTLZsAYQAWeRAGtIiuZFAVmpAObxGeCgUrU6xLtZ3YRQA'>Try</a></div></pre>\n<h2 id=\"null-and-undefined\" style=\"position:relative;\"><a href=\"#null-and-undefined\" aria-label=\"null and undefined permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Null and Undefined</h2>\n<p>In TypeScript, both <code>undefined</code> and <code>null</code> actually have their own types named <code>undefined</code> and <code>null</code> respectively.\nMuch like <code>void</code>, they’re not extremely useful on their own:</p>\n<pre class=\"shiki twoslash\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #008000\">// Not much else we can assign to these variables!</span>\n<span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> </span><span style=\"color: #1A1A1A\"><data-lsp lsp='let u: undefined'>u</data-lsp></span><span style=\"color: #000000\">:</span><span style=\"color: #1A1A1A\"> undefined </span><span style=\"color: #000000\">= </span><span style=\"color: #0000FF\"><data-lsp lsp='var undefined'>undefined</data-lsp></span><span style=\"color: #000000\">;</span>\n<span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> </span><span style=\"color: #1A1A1A\"><data-lsp lsp='let n: null'>n</data-lsp></span><span style=\"color: #000000\">:</span><span style=\"color: #1A1A1A\"> null </span><span style=\"color: #000000\">= </span><span style=\"color: #0000FF\">null</span><span style=\"color: #000000\">;</span></code><a href='https://www.typescriptlang.org/play/#code/PTAEDkHsBdQWwK4GMAWoCmAbAzu0B3PJAQwDtRjtsBLAc3OklGhXV1ADdiAna4gI0xsAhACghsBAC5QCUgBN0AM2ql080AF5ZC5avUBucelikZpBJkxbQFqwaA'>Try</a></div></pre>\n<p>By default <code>null</code> and <code>undefined</code> are subtypes of all other types.\nThat means you can assign <code>null</code> and <code>undefined</code> to something like <code>number</code>.</p>\n<p>However, when using the <code>--strictNullChecks</code> flag, <code>null</code> and <code>undefined</code> are only assignable to <code>unknown</code>, <code>any</code> and their respective types (the one exception being that <code>undefined</code> is also assignable to <code>void</code>).\nThis helps avoid <em>many</em> common errors.\nIn cases where you want to pass in either a <code>string</code> or <code>null</code> or <code>undefined</code>, you can use the union type <code>string | null | undefined</code>.</p>\n<p>Union types are an advanced topic that we’ll cover in a later chapter.</p>\n<blockquote>\n<p>As a note: we encourage the use of <code>--strictNullChecks</code> when possible, but for the purposes of this handbook, we will assume it is turned off.</p>\n</blockquote>\n<h2 id=\"never\" style=\"position:relative;\"><a href=\"#never\" aria-label=\"never permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Never</h2>\n<p>The <code>never</code> type represents the type of values that never occur.\nFor instance, <code>never</code> is the return type for a function expression or an arrow function expression that always throws an exception or one that never returns.\nVariables also acquire the type <code>never</code> when narrowed by any type guards that can never be true.</p>\n<p>The <code>never</code> type is a subtype of, and assignable to, every type; however, <em>no</em> type is a subtype of, or assignable to, <code>never</code> (except <code>never</code> itself).\nEven <code>any</code> isn’t assignable to <code>never</code>.</p>\n<p>Some examples of functions returning <code>never</code>:</p>\n<pre class=\"shiki twoslash\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #008000\">// Function returning never must not have a reachable end point</span>\n<span style=\"color: #0000FF\">function</span><span style=\"color: #000000\"> <data-lsp lsp='function error(message: string): never'>error</data-lsp>(</span><span style=\"color: #1A1A1A\"><data-lsp lsp='(parameter) message: string'>message</data-lsp></span><span style=\"color: #000000\">: string): never {</span>\n<span style=\"color: #000000\">  </span><span style=\"color: #0000FF\">throw</span><span style=\"color: #000000\"> </span><span style=\"color: #0000FF\">new</span><span style=\"color: #000000\"> <data-lsp lsp='var Error: ErrorConstructor&amp;#13;new (message?: string | undefined) => Error'>Error</data-lsp>(</span><span style=\"color: #1A1A1A\"><data-lsp lsp='(parameter) message: string'>message</data-lsp></span><span style=\"color: #000000\">);</span>\n<span style=\"color: #000000\">}</span>\n\n<span style=\"color: #008000\">// Inferred return type is never</span>\n<span style=\"color: #0000FF\">function</span><span style=\"color: #000000\"> <data-lsp lsp='function fail(): never'>fail</data-lsp>() {</span>\n<span style=\"color: #000000\">  </span><span style=\"color: #0000FF\">return</span><span style=\"color: #000000\"> <data-lsp lsp='function error(message: string): never'>error</data-lsp>(</span><span style=\"color: #A31515\">\"Something failed\"</span><span style=\"color: #000000\">);</span>\n<span style=\"color: #000000\">}</span>\n\n<span style=\"color: #008000\">// Function returning never must not have a reachable end point</span>\n<span style=\"color: #0000FF\">function</span><span style=\"color: #000000\"> <data-lsp lsp='function infiniteLoop(): never'>infiniteLoop</data-lsp>(): never {</span>\n<span style=\"color: #000000\">  </span><span style=\"color: #0000FF\">while</span><span style=\"color: #000000\"> (</span><span style=\"color: #0000FF\">true</span><span style=\"color: #000000\">) {}</span>\n<span style=\"color: #000000\">}</span></code><a href='https://www.typescriptlang.org/play/#code/PTAEDEFcDsGMBcCWB7aoBOBTel3UdAOajSYBum6oAtpAM7wnKMAWAhhaGxpm7OwCMANplCZoAE1AAHZAXgAoAGYwEKNJXTJ0ACmqY6dNoUwAuUA3QFCASnOkKVAN4LQoeCy0B3Eph8BRdC1dfUNjTBsAbgUAXwUFEFAASWglTUwpLBw8dwBPaVFEOl9HZVUkVFAlNkQhHRtQFzcs3A0g7R0AIgBlZH0PayqakQlOqNj4xKg4CrQWvEGHShp6RmhmUHZObiw+QRExSRk5aEUVGfVQAiUCRHhMABlkZGl6+3JlptAvFlrRHXg6EgEUacRiQA'>Try</a></div></pre>\n<h2 id=\"object\" style=\"position:relative;\"><a href=\"#object\" aria-label=\"object permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Object</h2>\n<p><code>object</code> is a type that represents the non-primitive type, i.e. anything that is not <code>number</code>, <code>string</code>, <code>boolean</code>, <code>symbol</code>, <code>null</code>, or <code>undefined</code>.</p>\n<p>With <code>object</code> type, APIs like <code>Object.create</code> can be better represented. For example:</p>\n<pre class=\"shiki twoslash\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">declare</span><span style=\"color: #000000\"> </span><span style=\"color: #0000FF\">function</span><span style=\"color: #000000\"> <data-lsp lsp='function create(o: object | null): void'>create</data-lsp>(</span><span style=\"color: #1A1A1A\"><data-lsp lsp='(parameter) o: object | null'>o</data-lsp></span><span style=\"color: #000000\">: object | null): void;</span>\n\n<span style=\"color: #008000\">// OK</span>\n<span style=\"color: #000000\"><data-lsp lsp='function create(o: object | null): void'>create</data-lsp>({ <data-lsp lsp='(property) prop: number'>prop</data-lsp>: </span><span style=\"color: #09835A\">0</span><span style=\"color: #000000\"> });</span>\n<span style=\"color: #000000\"><data-lsp lsp='function create(o: object | null): void'>create</data-lsp>(</span><span style=\"color: #0000FF\">null</span><span style=\"color: #000000\">);</span>\n\n<span style=\"color: #000000\"><data-lsp lsp='function create(o: object | null): void'>create</data-lsp>(</span><span style=\"color: #09835A\"><data-err>42</data-err></span><span style=\"color: #000000\">);</span>\n<span class=\"error\"><span>Argument of type '42' is not assignable to parameter of type 'object | null'.</span><span class=\"code\">2345</span></span><span class=\"error-behind\">Argument of type '42' is not assignable to parameter of type 'object | null'.</span><span style=\"color: #000000\"><data-lsp lsp='function create(o: object | null): void'>create</data-lsp>(</span><span style=\"color: #A31515\"><data-err>&quot;string&quot;</data-err></span><span style=\"color: #000000\">);</span>\n<span class=\"error\"><span>Argument of type '\"string\"' is not assignable to parameter of type 'object | null'.</span><span class=\"code\">2345</span></span><span class=\"error-behind\">Argument of type '\"string\"' is not assignable to parameter of type 'object | null'.</span><span style=\"color: #000000\"><data-lsp lsp='function create(o: object | null): void'>create</data-lsp>(</span><span style=\"color: #0000FF\"><data-err>false</data-err></span><span style=\"color: #000000\">);</span>\n<span class=\"error\"><span>Argument of type 'false' is not assignable to parameter of type 'object | null'.</span><span class=\"code\">2345</span></span><span class=\"error-behind\">Argument of type 'false' is not assignable to parameter of type 'object | null'.</span><span style=\"color: #000000\"><data-lsp lsp='function create(o: object | null): void'>create</data-lsp>(</span><span style=\"color: #0000FF\"><data-err><data-lsp lsp='var undefined'>undefined</data-lsp></data-err></span><span style=\"color: #000000\">);</span>\n<span class=\"error\"><span>Argument of type 'undefined' is not assignable to parameter of type 'object | null'.</span><span class=\"code\">2345</span></span><span class=\"error-behind\">Argument of type 'undefined' is not assignable to parameter of type 'object | null'.</span></code><a href='https://www.typescriptlang.org/play/#code/PTAEAEFMCdoe2gZwFygEwGYAsBWAUACaQDGANgIbSSgBmArgHbEAuAlnA6MVec5ABRxUcAEYArEs1AAfUAzqlSASlQA3OKwIBuPHhCgA8gGk83SLwEBvUAAd4N1AAZQAXyU6zF-vMXvdnvn4sND8AgQAiRGZoVgYAc3DQnkCaclJESCTzQMYiGljIAncgA'>Try</a></div></pre>\n<p>Generally, you won’t need to use this.</p>\n<h2 id=\"type-assertions\" style=\"position:relative;\"><a href=\"#type-assertions\" aria-label=\"type assertions permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Type assertions</h2>\n<p>Sometimes you’ll end up in a situation where you’ll know more about a value than TypeScript does.\nUsually this will happen when you know the type of some entity could be more specific than its current type.</p>\n<p><em>Type assertions</em> are a way to tell the compiler “trust me, I know what I’m doing.”\nA type assertion is like a type cast in other languages, but performs no special checking or restructuring of data.\nIt has no runtime impact, and is used purely by the compiler.\nTypeScript assumes that you, the programmer, have performed any special checks that you need.</p>\n<p>Type assertions have two forms.</p>\n<p>One is the <code>as</code>-syntax:</p>\n<pre class=\"shiki twoslash\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> </span><span style=\"color: #1A1A1A\"><data-lsp lsp='let someValue: any'>someValue</data-lsp></span><span style=\"color: #000000\">:</span><span style=\"color: #1A1A1A\"> any </span><span style=\"color: #000000\">= </span><span style=\"color: #A31515\">\"this is a string\"</span><span style=\"color: #000000\">;</span>\n\n<span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> </span><span style=\"color: #1A1A1A\"><data-lsp lsp='let strLength: number'>strLength</data-lsp></span><span style=\"color: #000000\">:</span><span style=\"color: #1A1A1A\"> number </span><span style=\"color: #000000\">= (</span><span style=\"color: #1A1A1A\"><data-lsp lsp='let someValue: any'>someValue</data-lsp></span><span style=\"color: #000000\"> </span><span style=\"color: #0000FF\">as</span><span style=\"color: #000000\"> string).<data-lsp lsp='(property) String.length: number'>length</data-lsp>;</span></code><a href='https://www.typescriptlang.org/play/#code/DYUwLgBAzg9gtiAagQ2AVxALgsgdgTwgF4IAiMACwEsoIadowAnK3Ac1IG4Aob0SKMwAyIdpWy40cAEYgmxCAApYCFOhA5agluwCUAOlBiKnIA'>Try</a></div></pre>\n<p>The other version is the “angle-bracket” syntax:</p>\n<pre class=\"shiki twoslash\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> </span><span style=\"color: #1A1A1A\"><data-lsp lsp='let someValue: any'>someValue</data-lsp></span><span style=\"color: #000000\">:</span><span style=\"color: #1A1A1A\"> any </span><span style=\"color: #000000\">= </span><span style=\"color: #A31515\">\"this is a string\"</span><span style=\"color: #000000\">;</span>\n\n<span style=\"color: #0000FF\">let</span><span style=\"color: #000000\"> </span><span style=\"color: #1A1A1A\"><data-lsp lsp='let strLength: number'>strLength</data-lsp></span><span style=\"color: #000000\">:</span><span style=\"color: #1A1A1A\"> number </span><span style=\"color: #000000\">= (&lt;string&gt;</span><span style=\"color: #1A1A1A\"><data-lsp lsp='let someValue: any'>someValue</data-lsp></span><span style=\"color: #000000\">).<data-lsp lsp='(property) String.length: number'>length</data-lsp>;</span></code><a href='https://www.typescriptlang.org/play/#code/DYUwLgBAzg9gtiAagQ2AVxALgsgdgTwgF4IAiMACwEsoIadowAnK3Ac1IG4Aob0SKMwAyIdpWy40cAEYgmxCAAoAPIJbsAfLAQp0IAJQA6UGIqcgA'>Try</a></div></pre>\n<p>The two samples are equivalent.\nUsing one over the other is mostly a choice of preference; however, when using TypeScript with JSX, only <code>as</code>-style assertions are allowed.</p>\n<h2 id=\"a-note-about-let\" style=\"position:relative;\"><a href=\"#a-note-about-let\" aria-label=\"a note about let permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>A note about <code>let</code></h2>\n<p>You may have noticed that so far, we’ve been using the <code>let</code> keyword instead of JavaScript’s <code>var</code> keyword which you might be more familiar with.\nThe <code>let</code> keyword is actually a newer JavaScript construct that TypeScript makes available.\nYou can read in the Handbook Reference on <a href=\"/docs/handbook/variable-declarations.html\">Variable Declarations</a> more about how <code>let</code> and <code>const</code> fix a lot of the problems with var.</p>\n<h2 id=\"about-number-string-boolean-symbol-and-object\" style=\"position:relative;\"><a href=\"#about-number-string-boolean-symbol-and-object\" aria-label=\"about number string boolean symbol and object permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>About <code>Number</code>, <code>String</code>, <code>Boolean</code>, <code>Symbol</code> and <code>Object</code></h2>\n<p>It can be tempting to think that the types <code>Number</code>, <code>String</code>, <code>Boolean</code>, <code>Symbol</code>, or <code>Object</code> are the same as the lowercase versions recommended above.\nThese types do not refer to the language primitives however, and almost never should be used as a type.</p>\n<pre class=\"shiki twoslash\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">function</span><span style=\"color: #000000\"> <data-lsp lsp='function reverse(s: String): String'>reverse</data-lsp>(</span><span style=\"color: #1A1A1A\"><data-lsp lsp='(parameter) s: String'>s</data-lsp></span><span style=\"color: #000000\">: <data-lsp lsp='interface String'>String</data-lsp>): <data-lsp lsp='interface String'>String</data-lsp> {</span>\n<span style=\"color: #000000\">  </span><span style=\"color: #0000FF\">return</span><span style=\"color: #000000\"> </span><span style=\"color: #1A1A1A\"><data-lsp lsp='(parameter) s: String'>s</data-lsp></span><span style=\"color: #000000\">.<data-lsp lsp='(method) String.split(separator: string | RegExp, limit?: number | undefined): string[] (+1 overload)'>split</data-lsp>(</span><span style=\"color: #A31515\">\"\"</span><span style=\"color: #000000\">).<data-lsp lsp='(method) Array&amp;lt;string>.reverse(): string[]'>reverse</data-lsp>().<data-lsp lsp='(method) Array&amp;lt;string>.join(separator?: string | undefined): string'>join</data-lsp>(</span><span style=\"color: #A31515\">\"\"</span><span style=\"color: #000000\">);</span>\n<span style=\"color: #000000\">}</span>\n\n<span style=\"color: #000000\"><data-lsp lsp='function reverse(s: String): String'>reverse</data-lsp>(</span><span style=\"color: #A31515\">\"hello world\"</span><span style=\"color: #000000\">);</span></code><a href='https://www.typescriptlang.org/play/#code/PTAEAEFMCdoe2gZwFygEwGYME4BQAzAVwDsBjAFwEs5jRpIA3GRSAChVAGVzpLiBzAJSpuvAaADeuUHUjlC0WogB0iAA4AbSuVYAiXYOX0mSNoYBWcPnoMBuXAF9cuY8za6AFpA0a4oAO4IGgAmdkA'>Try</a></div></pre>\n<p>Instead, use the types <code>number</code>, <code>string</code>, <code>boolean</code>, <code>object</code> and <code>symbol</code>.</p>\n<pre class=\"shiki twoslash\"><div class=\"language-id\">ts</div><div class='code-container'><code><span style=\"color: #0000FF\">function</span><span style=\"color: #000000\"> <data-lsp lsp='function reverse(s: string): string'>reverse</data-lsp>(</span><span style=\"color: #1A1A1A\"><data-lsp lsp='(parameter) s: string'>s</data-lsp></span><span style=\"color: #000000\">: string): string {</span>\n<span style=\"color: #000000\">  </span><span style=\"color: #0000FF\">return</span><span style=\"color: #000000\"> </span><span style=\"color: #1A1A1A\"><data-lsp lsp='(parameter) s: string'>s</data-lsp></span><span style=\"color: #000000\">.<data-lsp lsp='(method) String.split(separator: string | RegExp, limit?: number | undefined): string[] (+1 overload)'>split</data-lsp>(</span><span style=\"color: #A31515\">\"\"</span><span style=\"color: #000000\">).<data-lsp lsp='(method) Array&amp;lt;string>.reverse(): string[]'>reverse</data-lsp>().<data-lsp lsp='(method) Array&amp;lt;string>.join(separator?: string | undefined): string'>join</data-lsp>(</span><span style=\"color: #A31515\">\"\"</span><span style=\"color: #000000\">);</span>\n<span style=\"color: #000000\">}</span>\n\n<span style=\"color: #000000\"><data-lsp lsp='function reverse(s: string): string'>reverse</data-lsp>(</span><span style=\"color: #A31515\">\"hello world\"</span><span style=\"color: #000000\">);</span></code><a href='https://www.typescriptlang.org/play/#code/GYVwdgxgLglg9mABAJwKYDdXIM6oBTYBci2UyMYA5gJTGnlWIDeAUIiqlCMktgHTYADgBsYUPACIJ1Pmkw58MgFZwKk6QG4WAXxYs5WXJIAWqYcLiIA7nGTCAJpqA'>Try</a></div></pre>","headings":[{"value":"Boolean","depth":2},{"value":"Number","depth":2},{"value":"String","depth":2},{"value":"Array","depth":2},{"value":"Tuple","depth":2},{"value":"Enum","depth":2},{"value":"Unknown","depth":2},{"value":"Any","depth":2},{"value":"Void","depth":2},{"value":"Null and Undefined","depth":2},{"value":"Never","depth":2},{"value":"Object","depth":2},{"value":"Type assertions","depth":2},{"value":"A note about let","depth":2},{"value":"About Number, String, Boolean, Symbol and Object","depth":2}],"frontmatter":{"permalink":"/docs/handbook/basic-types.html","title":"Basic Types","disable_toc":null,"oneline":"Step one in learning TypeScript: The basics types."}},"prev":{"childMarkdownRemark":{"frontmatter":{"title":"The TypeScript Handbook","oneline":"Your first step to learn TypeScript","permalink":"/docs/handbook/intro.html"}}},"next":{"childMarkdownRemark":{"frontmatter":{"title":"Interfaces","oneline":"How to write an interface with TypeScript","permalink":"/docs/handbook/interfaces.html"}}}},"pageContext":{"id":"basic-types","slug":"/docs/handbook/basic-types.html","repoPath":"/packages/documentation/copy/en/handbook-v1/Basic Types.md","previousID":"5fb0db72-aeb7-5f60-9a01-0e7ce9f98b1e","nextID":"ff57dbef-1065-53e7-b2ca-b1e8b6fb2597","lang":"en","modifiedTime":"2020-08-07T17:00:36.335Z"}}}