Menu
CoddyTech
Course

C for JavaScript Developers

Move from JavaScript to C17: explicit types, pointers, bounded arrays, strings, ownership, structs and modular interfaces. Build a multi-file stock ledger and port two JavaScript programs.

JavaScript and C side by side

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

  1. Printing and Comments

    JavaScript console.log turns any value into text and ends the line for you. C printf uses a format string whose conversion specifiers must match the argument types; %d prints an int, and a mismatch is undefined behavior, not a TypeError. Comments use // or /*…

    JavaScript
    1const value = 7;2console.log(`value=${value}`);
    C
    1#include <stdio.h>2#include <stdlib.h>3#include <string.h>4#include <stddef.h>5#include <stdbool.h>6#include <limits.h>7#include <errno.h>8
    9int main(void) {10printf("value=%d\n",7);11return 0;12}
  2. Booleans and Branches

    JavaScript has a fixed list of falsy values: false, 0, NaN, "", null and undefined. In C a scalar zero is false and a nonzero scalar is true; a non-null pointer is true even if it points at an empty string. Use bool from stdbool.h when an explicit Boolean…

    JavaScript
    1console.log(Boolean(""));
    C
    1#include <stdio.h>2#include <stdlib.h>3#include <string.h>4#include <stddef.h>5#include <stdbool.h>6#include <limits.h>7#include <errno.h>8
    9int main(void) {10const char *s=""; printf("%s\n",s?"true":"false");11return 0;12}
  3. Arrays Need Lengths

    A JavaScript array carries its length and grows on demand. A C array has a fixed element count, and a function array parameter is adjusted to a pointer that does not carry that count. Pass a size_t length separately and respect it; C does not check subscripts.

    JavaScript
    1const a = [2, 4, 6];2console.log(a.length);
    C
    1#include <stdio.h>2#include <stdlib.h>3#include <string.h>4#include <stddef.h>5#include <stdbool.h>6#include <limits.h>7#include <errno.h>8
    9int main(void) {10int a[]={2,4,6};printf("%zu\n",sizeof a/sizeof a[0]);11return 0;12}
  4. Function Arguments Are Values

    JavaScript passes every argument by value. A number is copied, and an object argument copies the reference, so reassigning a parameter never changes the caller's variable. C parameters also receive copies of their values. Changing an int parameter cannot…

    JavaScript
    1function change(n) {2  n = 9;3}4let x = 2;5change(x);6console.log(x);
    C
    1#include <stdio.h>2#include <stdlib.h>3#include <string.h>4#include <stddef.h>5#include <stdbool.h>6#include <limits.h>7#include <errno.h>8static void change(int n){n=9;(void)n;}9int main(void) {10int x=2;change(x);printf("%d\n",x);11return 0;12}
  5. Addresses and Dereferencing

    JavaScript gives you references to objects but never their addresses, and nothing can point at a variable that holds a number. In C &object obtains an address and *pointer accesses the pointed-to object. Dereference only a valid pointer to a live object of…

    JavaScript
    1const box = [2];2const alias = box;3alias[0] = 5;4console.log(box[0]);
    C
    1#include <stdio.h>2#include <stdlib.h>3#include <string.h>4#include <stddef.h>5#include <stdbool.h>6#include <limits.h>7#include <errno.h>8
    9int main(void) {10int n=2;int *p=&n;*p=5;printf("%d\n",n);11return 0;12}
  6. Parsing with Status Results

    JavaScript number conversion does not throw: Number("12x") returns NaN, while parseInt("12x", 10) quietly returns 12 from the prefix. C library parsers use explicit status information. sscanf reports the number of successful assignments, but matching a prefix…

    JavaScript
    1const text = "12x";2console.log(parseInt(text, 10), /^[0-9]+$/.test(text));
    C
    1#include <stdio.h>2#include <stdlib.h>3#include <string.h>4#include <stddef.h>5#include <stdbool.h>6#include <limits.h>7#include <errno.h>8
    9int main(void) {10const char *s="12x";int ok=*s!=0;for(size_t i=0;s[i];i++)if(s[i]<'0'||s[i]>'9')ok=0;printf("%d\n",ok);11return 0;12}

Syllabus

10 chapters48 lessons1 project48 challenges99 quiz questions

More courses for JavaScript developers

Learn C from another language

Frequently asked questions

Who is C for JavaScript Developers for?

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

Do I need to know C already?

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

How many lessons does C for JavaScript Developers have?

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

What does C for JavaScript Developers cover?

The course is organized into chapters covering: Compile and Compute, Decisions and Loops, Arrays and Text, Functions and Interfaces, and more.

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

Get started