C++ for TypeScript Developers
Transfer TypeScript experience to C++17: values, flow, functions, containers, headers, classes, virtual dispatch, RAII, and move ownership. Build a connected library desk.
TypeScript and C++ side by side
The same program in TypeScript and in C++, from the lessons of this course.
Strings and Output
TypeScript strings are immutable primitives, and length counts UTF-16 code units. C++ std::string owns a mutable byte sequence; you can assign to one character in place, and stream insertion formats values. Length counts bytes, not Unicode characters, so the…
TypeScript1const name: string = "café";2const title = "C" + name.slice(1);3console.log(title, 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(){14 std::string name="café";15 name[0]='C';16 std::cout<<name<<" "<<name.size()<<"\n";17}Text Equality
TypeScript === compares string primitives by text but compares objects and arrays by reference, so two equal-looking objects are not ===. C++ equality likewise depends on the operand type. C++ std::string equality compares contents. Raw pointer equality…
TypeScript1const a = { tag: "red" };2const b = { tag: "red" };3console.log(a.tag === b.tag, 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(){14 std::string a="red",b="red";15 std::cout<<std::boolalpha<<(a==b)<<" "<<(&a==&b)<<"\n";16}Fixed-size Arrays
TypeScript arrays are reference objects that can always grow, and assigning one to another variable shares it. A tuple type can fix the length, but only at compile time. C++ std::array<T,N> is a fixed-size value type. Its size is part of its type, and normal…
TypeScript1const a: number[] = [4, 5, 6];2const b = a;3b[1] = 9;4console.log(a.length, a[1], a[7]);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(){14 std::array<int,3> a{4,5,6};15 auto b=a;16 b[1]=9;17 std::cout<<a.size()<<" "<<a.at(1)<<" "<<b.at(1)<<"\n";18}Value Copies
In TypeScript, arrays and objects are references: const b = a makes a second name for the same array, and you copy with a spread such as [...a]. C++ works the other way round. auto b = a; on a std::vector or std::string copies every element into storage that…
TypeScript1const a: number[] = [4];2const alias = a;3const copy = [...a];4alias.push(9);5copy.push(7, 8);6console.log(a.length, alias.length, copy.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::vector<int> a{4};auto b=a;b.push_back(9);b.push_back(8);15std::vector<int>* p=&a;p->push_back(1);16std::cout<<a.size()<<" "<<b.size()<<"\n";17}Functions and Returns
TypeScript functions live at the top level of a module, function declarations are hoisted, and a function with no return gives its caller undefined. C++ free functions also need no enclosing class, but a function must be declared before the line that calls…
TypeScript1function triple(n: number): number {2 return 3 * n;3}4function log(n: number) {5 console.log(n);6}7const r = log(triple(4));8console.log(r);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>12int triple(int n);13void show(int n){std::cout<<n<<"\n";}14int main(){15show(triple(4));16triple(5);17}18int triple(int n){return 3*n;}Streams and Exact Parsing
In TypeScript, Number(text) returns NaN for text that is not a number but quietly turns an empty string into 0, while parseInt accepts a leading number and ignores what follows. C++ stream extraction reports success through the stream state instead. in >> n…
TypeScript1console.log(Number("7"), Number("7x"), Number(""), parseInt("7x", 10));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::istringstream in("oak 7x");std::string word;int n=0;char extra=' ';15if(in>>word>>n)std::cout<<word<<"/"<<n;16if(in>>extra)std::cout<<" trailing "<<extra;17std::cout<<"\n";18}
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 TypeScript Developers for?
For people who already write TypeScript and want to learn C++. Each lesson starts from TypeScript 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 TypeScript basics: variables, conditions, loops, functions and collections.
How many lessons does C++ for TypeScript Developers have?
C++ for TypeScript Developers contains 48 interactive lessons you can complete at your own pace.
What does C++ for TypeScript 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 TypeScript Developers free?
Yes. Every course on Coddy is free to start. You can complete lessons in your browser without any downloads or signup.