C++ for JavaScript Developers
Transfer JavaScript experience to C++17: values, flow, functions, containers, headers, classes, virtual dispatch, RAII, and move ownership. Build a connected library desk.
JavaScript and C++ side by side
The same program in JavaScript and in C++, from the lessons of this course.
Strings and Output
A JavaScript string is an immutable sequence of UTF-16 code units: methods such as toUpperCase return a new string, and length counts code units. C++ std::string owns a mutable byte sequence, so you can change a character or append in place, and stream…
JavaScript1const name = "oak";2const upper = name.toUpperCase();3console.log(name, upper, name.length);C++1#include <iostream>2#include <string>3#include <vector>4#include <array>5#include <map>6#include <set>7#include <algorithm>8#include <memory>9#include <sstream>10#include <stdexcept>11#include <utility>12 13int main(){14std::string name="oak";15name[0]='O';16name+="s";17std::cout<<name<<" "<<name.size()<<"\n";18}Text Equality
JavaScript === compares strings by content because they are primitives, but arrays and objects compare by identity, so two separately built arrays are never equal. C++ operator behavior depends on the declared operand types. std::string equality compares…
JavaScript1const a = ["red"];2const b = ["red"];3console.log(a[0] === b[0]);4console.log(a === b);C++1#include <iostream>2#include <string>3#include <vector>4#include <array>5#include <map>6#include <set>7#include <algorithm>8#include <memory>9#include <sstream>10#include <stdexcept>11#include <utility>12 13int main(){14std::string a="red",b="red";15std::vector<std::string> x{a},y{b};16std::cout<<std::boolalpha<<(a==b)<<" "<<(x==y)<<"\n";17}Fixed-size Arrays
A JavaScript array is a resizable object: assigning it to another variable shares the same array, an index past the end reads undefined, and at(-1) counts from the end. C++ std::array<T,N> is a fixed-size value type. Its size is part of its type, so it cannot…
JavaScript1const items = [4, 8];2const alias = items;3alias.push(12);4console.log(items.length, items.at(-1));5console.log(items[5]);C++1#include <iostream>2#include <string>3#include <vector>4#include <array>5#include <map>6#include <set>7#include <algorithm>8#include <memory>9#include <sstream>10#include <stdexcept>11#include <utility>12 13int main(){14std::array<int,3> a{4,5,6};15auto b=a;16b[0]=9;17std::cout<<a.size()<<" "<<a[0]<<" "<<b.at(0)<<"\n";18}Value Copies
In JavaScript, assigning an array or object copies only the reference, and spread syntax or slice makes a shallow copy whose nested arrays are still shared; only structuredClone copies deeply. C++ copies by value: auto b = a; copies a std::vector element by…
JavaScript1const original = [[1]];2const alias = original;3const copy = [...original];4copy[0].push(2);5copy.push([3]);6console.log(JSON.stringify(original), alias === original);C++1#include <iostream>2#include <vector>3 4int main() {5 std::vector<std::vector<int>> a{{1}};6 auto b = a;7 b[0].push_back(2);8 b.push_back({3});9 std::cout << a.size() << " " << a[0].size() << " " << b.size() << " " << b[0].size() << "\n";10}Functions and Returns
JavaScript functions are values with untyped parameters: a missing argument becomes undefined, a string can arrive where a number was meant, and a function without return yields undefined. None of that is checked before the call runs. A C++ function…
JavaScript1function twice(value) {2 return value * 2;3}4function noReturn(value) {5 value * 2;6}7console.log(twice(4), twice("4"), twice(), noReturn(4));C++1#include <iostream>2 3int triple(int n) {4 return 3 * n;5}6 7int main() {8 int result = triple(4);9 triple(5);10 std::cout << result << "\n";11}Streams and Exact Parsing
JavaScript number conversion rarely fails loudly: parseInt reads a leading numeric prefix and ignores the rest, while Number returns NaN for text that is not entirely a number, and neither throws. C++ stream extraction reports success through stream state. in…
JavaScript1const [word, number] = "oak 7x".split(" ");2console.log(`${word}/${parseInt(number, 10)}/${Number(number)}`);C++1#include <iostream>2#include <sstream>3#include <string>4 5int main() {6 std::istringstream in("oak 7x");7 std::string word;8 int n;9 if (in >> word >> n) std::cout << word << "/" << n << "\n";10 std::string rest;11 if (in >> rest) std::cout << "trailing " << rest << "\n";12}
Syllabus
10 chapters48 lessons1 project48 challenges99 quiz questionsC++ Files and Values
6 lessonsConditions and Iteration
5 lessonsStandard Containers
5 lessonsCopies and Algorithms
5 lessonsFunctions and Templates
5 lessonsParsing and Lifetime
5 lessonsObjects and Invariants
6 lessonsComposition and Ownership
5 lessonsProject: Library Desk
4 lessonsFinal Challenges
2 lessonsFrequently 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: C++ Files and Values, Conditions and Iteration, Standard Containers, Copies and Algorithms, 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.