Execute Program

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:
    4Pass Icon
  • >
    const length: string = 'four'.length;
    Result:
    type error: Type 'number' is not assignable to type 'string'.Pass Icon
  • >
    let s: string = (123).toString();
    s;
    Result:
    '123'Pass Icon
  • >
    let n: number = (123).toString();
    n;
    Result:
    type error: Type 'string' is not assignable to type 'number'.Pass Icon