Basics

Even though the syntax and semantics of Imba is much more related to Ruby than JavaScript, it does compile down to plain performant JavaScript, and is fully compatible with any existing JavaScript library. Imba does not extend any native types from JavaScript. Arrays are arrays, strings are strings, numbers are numbers, classes are constructors with prototypes and so forth. If you simply like Imba better, there is no reason not to write your npm package in Imba, even if it is supposed to be used in the general JavaScript ecosystem. In fact, Imba produces very readable JavaScript, by keeping your indentation, comments, and coding style.

Interoperability

Imba compiles to very straight-forward JavaScript. All the fundamental types are the same as in JavaScript, so for documentation about available methods see MDN Object, Function, String, Number, RegExp, Array, Date, Math.

var single = 'single quotes' var double = "double quotes" var interpolation = "string has {double}"var single = 'single quotes'; var double = "double quotes"; var interpolation = ("string has " + double);
var integer = 42 var float = 42.10var integer = 42; var float = 42.10;
var object = {name: 'Imba', type: 'Language'}var object = {name: 'Imba',type: 'Language'};
var array = [1,2,3,4,5]var array = [1,2,3,4,5];
var regex = /number is (\d+)/var regex = /number is (\d+)/;
for num in [1,2,3] num for own key, value of object valuefor (let i = 0, items = [1,2,3], len = items.length; i < len; i++) { items[i]; }; for (let o = this.object(), value, i = 0, keys = Object.keys(o), l = keys.length, key; i < l; i++){ key = keys[i];value = o[key];value; };
def hello return 'world' console.log hellofunction hello(){ return 'world'; }; console.log(hello());
class Todo def initialize title @title = title @completed = no def complete @completed = yesfunction Todo(title){ this._title = title; this._completed = false; }; Todo.prototype.complete = function (){ return this._completed = true; };
var item item = 100 # set value of item item ?= 100 # set if value is null or undefined item &= 100 # set if value is not null or undefined # comparators item == 10 # check item === 10 # strictly equal item != 10 # not equal item !== item # strictly not equal item > 10 # greater than item < 10 # less than item >= 10 # greater than or equal item <= 10 # less than or equalvar item; item = 100; // set value of item (item == null) ? (item = 100) : item; // set if value is null or undefined item &= 100; // set if value is not null or undefined // comparators item == 10; // check item === 10; // strictly equal item != 10; // not equal item !== item; // strictly not equal item > 10; // greater than item < 10; // less than item >= 10; // greater than or equal item <= 10; // less than or equal