Menu
CoddyTech
Course

TypeScript for C Developers

Learn TypeScript and the JavaScript runtime from C: values, control flow, callbacks, typed collections, validation and object modules. Build a connected order-processing project and port two source programs.

C and TypeScript side by side

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

  1. Run TypeScript

    C compiles translation units and links an executable with a main function. TypeScript instead emits JavaScript executed by Node, and its types are erased. This course introduces JavaScript variables, arrays, objects and functions without assuming prior…

    C
    1#include <stdio.h>2#include <stdlib.h>3#include <string.h>4#include <stdbool.h>5#include <ctype.h>6#include <errno.h>7#include <math.h>8
    9int main(void) {10    printf("Hello, %s!\n", "Ada");11    return 0;12}
    TypeScript
    1const name: string = "Ada";2console.log(`Hello, ${name}!`);3export {};
  2. Numbers and Conversion

    C strtol reports conversion progress through an end pointer and range failures through errno; the caller checks both. JavaScript Number instead can yield NaN, and blank text converts to zero. Explicit conversion and validation replace the C end-pointer checks…

    C
    1#include <stdio.h>2#include <stdlib.h>3#include <string.h>4#include <stdbool.h>5#include <ctype.h>6#include <errno.h>7#include <math.h>8
    9int main(void) {10    const char *text = "12";11    char *end;12    errno = 0;13    long value = strtol(text, &end, 10);14    if (errno || end == text || *end != '\0') return 1;15    printf("%ld\n", value + 3);16    return 0;17}
    TypeScript
    1const value: number = Number("12");2console.log(value + 3);3export {};
  3. Arrays and Slice

    C has no standard array-slice value: pointer-and-length views share storage, while copying elements into another array creates independent slots. JavaScript slice creates a new outer array. Its end bound is excluded, and absent bracket reads return undefined…

    C
    1#include <stdio.h>2#include <stdlib.h>3#include <string.h>4#include <stdbool.h>5#include <ctype.h>6#include <errno.h>7#include <math.h>8
    9int main(void) {10    int values[] = {1, 2, 3, 4};11    int middle[2];12    memcpy(middle, values + 1, sizeof middle);13    printf("[%d,%d]\n", middle[0], middle[1]);14    return 0;15}
    TypeScript
    1const values: number[] = [1, 2, 3, 4];2console.log(JSON.stringify(values.slice(1, -1)));3export {};
  4. For-of and Array Values

    C normally iterates arrays through an index or pointer with an explicit length. JavaScript for-of yields values; for-in enumerates keys and is not a C indexed array loop. Use entries when you need both index and value.

    C
    1#include <stdio.h>2#include <stdlib.h>3#include <string.h>4#include <stdbool.h>5#include <ctype.h>6#include <errno.h>7#include <math.h>8
    9int main(void) {10    int values[] = {3, -1, 2};11    int total = 0;12    for (size_t i = 0; i < sizeof values / sizeof values[0]; ++i) {13        if (values[i] > 0) total += values[i];14    }15    printf("%d\n", total);16    return 0;17}
    TypeScript
    1let total: number = 0;2for (const value of [3, -1, 2]) { if (value > 0) total += value; }3console.log(total);4export {};
  5. Truthiness Is Not Emptiness

    C collection emptiness is usually represented by an explicit length, not by testing a pointer to its storage. A non-null pointer can accompany zero elements. JavaScript treats an empty array as true. The source nonempty check and target truthiness check…

    C
    1#include <stdio.h>2#include <stdlib.h>3#include <string.h>4#include <stdbool.h>5#include <ctype.h>6#include <errno.h>7#include <math.h>8
    9int main(void) {10    size_t count = 0;11    puts(count > 0 ? "true" : "false");12    return 0;13}
    TypeScript
    1const value: unknown = [];2console.log(Boolean(value));3export {};
  6. Annotations and Inference

    C distinguishes integer and floating-point types, with usual arithmetic conversions governing mixed expressions. TypeScript number uses JavaScript floating-point arithmetic. Annotating a count as number does not provide C integer widths, overflow or division…

    C
    1#include <stdio.h>2#include <stdlib.h>3#include <string.h>4#include <stdbool.h>5#include <ctype.h>6#include <errno.h>7#include <math.h>8
    9int main(void) {10    double price = 2.5;11    int count = 4;12    printf("%g\n", price * count);13    return 0;14}
    TypeScript
    1const price: number = 2.5;2const count = 4;3console.log(price * count);4export {};

Syllabus

12 chapters48 lessons1 project48 challenges96 quiz questions

Start Here

1 lesson

Final Challenges

2 lessons

More courses for C developers

Learn TypeScript from another language

Frequently asked questions

Who is TypeScript for C Developers for?

For people who already write C and want to learn TypeScript. Each lesson starts from C 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 C basics: variables, conditions, loops, functions and collections.

How many lessons does TypeScript for C Developers have?

TypeScript for C Developers contains 48 interactive lessons you can complete at your own pace.

What does TypeScript for C Developers cover?

The course is organized into chapters covering: Start Here, Runtime Values, Runtime Collections, Runtime Control Flow, and more.

Is TypeScript for C 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 C Developers for free

Get started