Go for JavaScript Developers
Transfer your JavaScript experience to Go: typed values, control flow, slices, functions, methods, interfaces and error handling. Build a tested multi-file order pipeline.
JavaScript and Go side by side
The same program in JavaScript and in Go, from the lessons of this course.
Files and the first run
JavaScript executes script or module statements. Go compiles all files in a package and starts at main. Same-package Go functions need no file import, but each file declares its standard-library imports.
JavaScript1console.log("JavaScript", 3);Go1package main2import ("fmt")3 4func main(){fmt.Println("Go", 3)}If and scoped names
JavaScript let is block-scoped, but an if condition can use truthy values. Go requires braces and bool; an initializer before the condition can declare a variable shared by the if and else branches only.
JavaScript1const n="go".length; if(n>1){console.log("long");}else{console.log("short");}Go1package main2import ("fmt")3 4func main(){if n := len("go"); n > 1 { fmt.Println("long") } else { fmt.Println("short") }}Arrays are values
JavaScript arrays are mutable reference objects; spreading creates a shallow copy. Go arrays copy on assignment and include length in the type. Go slices are the more flexible collection, but have reference-sharing behavior of their own.
JavaScript1const a=[3,5];const b=[...a];b[0]=9;console.log(a[0],b[0]);Go1package main2import ("fmt")3 4func main(){a:=[2]int{3,5}5b:=a6b[0]=97fmt.Println(a[0],b[0])}Typed function contracts
JavaScript functions accept dynamic arguments and may use default parameters. Go declares parameter and result types, passes values and does not support defaults or overloads. Shared package functions can live in separate files.
JavaScript1function isEven(n){return n%2===0;}console.log(isEven(6));Go1package main2import ("fmt")3func IsEven(n int) bool { return n%2==0 }4func main(){fmt.Println(IsEven(6))}Struct values
JavaScript object assignment shares identity; object spread creates a shallow field copy. Go struct assignment already copies fields by value. Pointer, map or slice fields can still reference shared data after a struct copy.
JavaScript1const a={text:"old"};const b={...a};b.text="new";console.log(a.text,b.text);Go1package main2import ("fmt")3type Label struct { Text string }4func main(){a:=Label{Text:"old"}5b:=a6b.Text="new"7fmt.Println(a.Text,b.Text)}Errors are returned values
JavaScript uses throw/catch for many failures and promises for asynchronous failures. Go normally returns an error value for recoverable failure. Callers check it explicitly; panic/recover is not the routine translation of try/catch.
JavaScript1function positive(n){if(n<=0)throw new Error("not positive");return n;}try{positive(-2);}catch(e){console.log("rejected");}Go1package main2import ("fmt";"errors")3func Positive(n int)(int,error) { if n<=0{return 0,errors.New("not positive")};return n,nil }4func main(){_,e:=Positive(-2)5fmt.Println(e!=nil)}
Syllabus
9 chapters48 lessons1 project48 challenges99 quiz questionsValues and expressions
7 lessonsControl flow
5 lessonsCollections
6 lessonsFunctions and pointers
6 lessonsTypes and behavior
8 lessonsErrors and organization
6 lessonsText and absence
4 lessonsOrder pipeline
Project4 lessonsFinal challenges
2 lessonsFrequently asked questions
Who is Go for JavaScript Developers for?
For people who already write JavaScript and want to learn Go. Each lesson starts from JavaScript you know and shows how Go does the same thing, so you skip the beginner basics.
Do I need to know Go already?
No. The course starts with your first Go program. You need JavaScript basics: variables, conditions, loops, functions and collections.
How many lessons does Go for JavaScript Developers have?
Go for JavaScript Developers contains 48 interactive lessons you can complete at your own pace.
What does Go for JavaScript Developers cover?
The course is organized into chapters covering: Values and expressions, Control flow, Collections, Functions and pointers, and more.
Is Go 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.