Basics¶
Variables¶
Kotlin val maps to JavaScript const, and var maps to let.
Transpiles to:
Functions¶
Functions are transpiled to standard JavaScript function declarations.
Transpiles to:
Control Flow¶
If-Else¶
if statements work as expected.
Transpiles to:
When¶
Kotlin when expressions are transpiled to if/else if/else chains.
Transpiles to:
When used as an expression, it is wrapped in an immediately invoked function expression (IIFE):
Transpiles to:
Loops¶
For Loops¶
for loops over ranges are transpiled to standard for loops.
Transpiles to:
Loops over collections use for...of.
Transpiles to:
While Loops¶
Transpiles to:
Operators¶
Equality¶
Kotlin's == and != always map to JavaScript's strict equality operators === and !==.
Elvis Operator¶
The elvis operator ?: maps to the JavaScript nullish coalescing operator ??.
Transpiles to:
String Templates¶
Kotlin string templates are transpiled to JavaScript template literals.
Transpiles to: