myriad

Install this vscode extension for syntax highlight

Declarations

Comments

Data Types

If Statements

let val;

if (x > 0) {
  val = "positive";
 else if (x < 0) {
  val = "negative";
} else {
  val = "equal";
}

print(val);

Curly braces are optional of body has single statement

let val;

if (x > 0) val = "positive";
else if (x < 0) val = "negative";
else val = "equal";

print(val);

Also parenthesis are optional in test condition.

let val;

if x > 0
  val = "positive";
else if x < 0
  val = "negative";
else
  val = "equal";

print(val);

Function Statements

func log(val){
    print(val);
}

Funcions return last expression by default

func add(x, y){
    x + y;
}

Or you can use the return keyword

func add(x, y){
    return x + y;
}

Function Expressions

You can define functions as a expressions too. Similar to function statements without function name.

const add = func (x, y) {
  return x + y;
}

Loops

Try Catch

try {
  const x = calculateValue();

  if (x == null) {
    throw "Something went wrong";
  }
} catch (err) {
  print(err);
}

Import and Export

String methods

Array methods

Global Functions

Global Objects

Math

Json

dt

http

fs

run_node