Menu
CoddyTech
Course

TypeScript for JavaScript Developers

Bring JavaScript experience to typed contracts, narrowing, functions, collections and class modules. Build and test a validated order-processing tool in TypeScript.

JavaScript and TypeScript side by side

The same program in JavaScript and in TypeScript, from the lessons of this course.

  1. Run TypeScript

    TypeScript adds a checker to JavaScript. Types disappear before execution; strings, numbers and template literals still behave as JavaScript. The editor runs the TypeScript target. The JavaScript examples are comparison programs. Run the supplied two-file…

    JavaScript
    1const name = "Ada";2console.log(`Hello, ${name}!`);
    TypeScript
    1const name: string = "Ada";2console.log(`Hello, ${name}!`);
  2. Annotations and Inference

    Keep JavaScript arithmetic and add annotations at boundaries. A variable initialized to a number usually needs no annotation because inference already knows its type. A parameter needs a declared contract here. TypeScript number is still the JavaScript…

    JavaScript
    1const price = 2.5;2const count = 4;3console.log(price * count);
    TypeScript
    1const price: number = 2.5;2const count = 4;3console.log(price * count);
  3. Narrowing with typeof

    TypeScript follows branches and narrows a union inside each branch. The guard itself is ordinary JavaScript. Double numeric inputs; for strings return length. For this exercise strings contain ASCII characters, so string length also equals the character…

    JavaScript
    1function measure(value) { return typeof value === "number" ? value * 2 : value.length; }2console.log(measure("abc"));
    TypeScript
    1function measure(value: number | string): number { return typeof value === "number" ? value * 2 : value.length; }2console.log(measure("abc"));
  4. Function Parameters

    Annotate parameter and return boundaries while preserving JavaScript defaults and rest arguments. A default is used for undefined or an omitted argument, not for zero or null. Sum all values and multiply by factor, defaulting to two when factor is absent.…

    JavaScript
    1function total(factor = 2, ...values) { return values.reduce((s, n) => s + n, 0) * factor; }2console.log(total(undefined, 2, 3));
    TypeScript
    1function total(factor: number = 2, ...values: number[]): number { return values.reduce((s, n) => s + n, 0) * factor; }2console.log(total(undefined, 2, 3));
  5. Readonly and Copies

    Readonly prevents mutation through a typed reference; it does not freeze the JavaScript object. Sorting mutates an array, so copy before sorting. Return ascending numeric values without changing input. JavaScript default sort compares string forms; use a…

    JavaScript
    1const values = [10, 2, 1];2console.log(JSON.stringify([...values].sort((a, b) => a - b)));
    TypeScript
    1const values: readonly number[] = [10, 2, 1];2console.log(JSON.stringify([...values].sort((a, b) => a - b)));
  6. Errors and Runtime Checks

    JSON.parse performs parsing, not schema validation. Assign its result to unknown and check the runtime category before doing arithmetic. Here input is a string containing another JSON document: parse it and double finite numbers; return invalid for malformed…

    JavaScript
    1try { const value = JSON.parse("{"); console.log(value); } catch (error) { console.log(error instanceof SyntaxError ? "invalid" : "unexpected"); }
    TypeScript
    1try { const value: unknown = JSON.parse("{"); console.log(value); } catch (error: unknown) { console.log(error instanceof SyntaxError ? "invalid" : "unexpected"); }

Syllabus

8 chapters32 lessons1 project32 challenges60 quiz questions

More courses for JavaScript developers

Learn TypeScript from another language

Frequently asked questions

Who is TypeScript for JavaScript Developers for?

For people who already write JavaScript and want to learn TypeScript. Each lesson starts from JavaScript you know and shows how TypeScript does the same thing, so you skip the beginner basics.

Do I need to know TypeScript already?

No. The course starts with your first TypeScript program. You need JavaScript basics: variables, conditions, loops, functions and collections.

How many lessons does TypeScript for JavaScript Developers have?

TypeScript for JavaScript Developers contains 32 interactive lessons you can complete at your own pace.

What does TypeScript for JavaScript Developers cover?

The course is organized into chapters covering: Start Here, Typed Contracts, Typed Flow, Typed Functions, and more.

Is TypeScript for JavaScript Developers free?

Yes. Every course on Coddy is free to start. You can complete lessons in your browser without any downloads or signup.

Coddy programming languages illustration

Start TypeScript for JavaScript Developers for free

Get started