The following tables show side-by-side mappings between JavaScript and Elm. A lot of things are very similar, especially once you get used to the relatively minor syntactic difference.
The following tables show side-by-side mappings between JavaScript and Elm. A lot of things are very similar, especially once you get used to the relatively minor syntactic difference.
JavaScript | Elm |
---|---|
3 | 3 |
3.1415 | 3.1415 |
"Hello world!" | "Hello world!" |
Multiline strings not widely supported | """multiline string""" |
'Hello world!' | Cannot use single quotes for strings |
No distinction between characters and strings | 'a' |
true | True |
[1,2,3] | [1,2,3] |
JavaScript | Elm |
---|---|
{ x: 3, y: 4 } | { x = 3, y = 4 } |
point.x | point.x |
point.x = 42 | { point | x = 42 } |
JavaScript | Elm |
---|---|
function(x, y) { return x + y; } | \x y -> x + y |
Math.max(3, 4) | max 3 4 |
Math.min(1, Math.pow(2, 4)) | min 1 (2^4) |
numbers.map(Math.sqrt) | List.map sqrt numbers |
points.map(function(p) { return p.x }) | List.map .x points |
JavaScript | Elm |
---|---|
3 > 2 ? 'cat' : 'dog' | if 3 > 2 then "cat" else "dog" |
var x = 42; ... | let x = 42 in ... |
return 42 | Everything is an expression, no need for return |
JavaScript | Elm |
---|---|
'abc' + '123' | "abc" ++ "123" |
'abc'.length | String.length "abc" |
'abc'.toUpperCase() | String.toUpper "abc" |
'abc' + 123 | "abc" ++ String.fromInt 123 |