Skip to content
Permalink
Branch: master
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
181 lines (166 sloc) 1.92 KB

NectarScript Definition (NS)

NS-v0.1

Types

  • Undefined
var undef;
  • Null
var _null = null;
  • Boolean
var bool = false;
  • String
var string = "a string";
  • Number (int)
var number = 3;
  • Array
var arr = [0, "abc", [1,2,3]];
var aString = arr[1];
  • Object
var obj = {"key": "value", 0:1 };
var aString = obj.key;

Semantics

  • for
for(var i = 0; i < 3; i++)
{
  console.log(i);
}
  • while
var i = 3;
while(i > 0)
{
  console.log(i);
  i--;
}
  • do while
var i = 3;
do
{
  console.log(i);
  i--;
}while(i > 0)

Conditions

  • if
var i = 0;
if(i < 1)
{
  // code block here
}
  • if / else
var i = 0;
if(i < 1)
{
 // code block here
}
else 
{
 // code block here
}
  • if / else if / else
var i = 0;
if(i < 1)
{
 // code block here
}
else if(i == 2)
{
  // code block here
}
else 
{
 // code block here
}

Operators

  • +
var a = "string" + "string"; // "stringstring"
var b = "string" + 1; // "string1"
var c = 1 + 1; // 2
var d = 1 + "string"; // 0
var e = 1 + "string" + 2; // 2
  • -
var a = 1-1; // 0
  • /
var a = 4/2; // 2
  • *
var a = 2*2; // 4
  • %
var a = 10%3; // 1
  • >
var a = 1 > 0; // true
  • <
var a = 1 < 2; // true
  • >=
var a = 1 >= 1; // true
  • <=
var a = 1 <= 1; // true
  • =
var a = 1; // 1
  • ==
var a = 1 == 1; // true

Functions

  • Normal function
function myFunc(x,y,z)
{
  console.log(x+1);
}
  • Nested function
function myFunc(x,y,z)
{
  function nestedFunction()
  {
    console.log(z); // same block
  }
  nestedFunction();
}

Exceptions

  • try/catch block
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.