Skip to content

Quick Javascript / Kotlin comparison

This part of the guide might be helpful to map noteworthy knowledge from javascript to kotlin. Detailed kotlin introduction will be proper handled in the next section.

Online playgrounds

Kotlin has one, brand new.

KotlinJavascript
play.kotlinlang.orgplaycode.io
codesandbox.io
stackblitz.com
codepen.io
npm.runkit.com

Command line interpreters/compilers

Kotlin is general purpose, compiled language. There is a compiler and it's installable through various ways.

For linux, sdkman is the best choice, for mac homebrew.

Javascript can run on command line as well in the form of node.js, and there are several ways to install it.

Online package registries

Kotlin is heavily dependent of jvm and maven registry. There is no equivalent tool to npm or yarn, maven and gradle does project management work but lack a good amount of features. We'll discuss them later.

Notable language features and its equivalents

There will be a more detailed section on it in the next chapter.

Variables

KotlinJavascript
// regular variables
var x: Intvar x
var x = 10 // type inferencelet x
// constants
val x: Int = 10const x = 10
val x = 10
// compile-time constants
const x = 10 // checked// there is no such thing
const x = something() // error

Data structures

KotlinJavascript
// lists
val x = listOf(1,2,3)const x = [1,2,3]
val y = setOf(1,2,2,3)const y = new Set([1,2,3])
// maps
val x = mapOf("a" to 1, "b" to 2)const x = { a: 1, b: 2 }
// classes
class Xclass X {}
class Y(public val x: String)class X { constructor(x) { this.x = x} }

We'll discuss classes in details later.

Destructuring

KotlinJavascript
// lists
val (first, second) = listOf(1,2,3)const [first, second] = [1,2,3]
// maps (works with data classes too)
val (first, second) = mapOf("a" to 1, "b" to 2)const {a, b} = {a: 1, b: 2}
const {a:first, b:second} = {a: 1, b: 2}

Communities to talk about the language

Noteworthy extras