TypeScript Basics: JavaScript Builtins
Welcome to the JavaScript Builtins lesson!
This lesson is shown as static text below. However, it's designed to be used interactively. Click the button below to start!
TypeScript knows the types of built-in JavaScript functions and methods.
(Some of these examples cause type errors. You can answer those examples with
type error.)>
const len: number = 'four'.length;len;Result:
4
>
const length: string = 'four'.length;Result:
type error: Type 'number' is not assignable to type 'string'.
>
let s: string = (123).toString();s;Result:
'123'
>
let n: number = (123).toString();n;Result:
type error: Type 'string' is not assignable to type 'number'.