- Notifications
You must be signed in to change notification settings - Fork14
A new statically typed programming language, syntactically like TypeScript.
License
StaticScript/StaticScript
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
StaticScript is a statically typed and strongly typed programming language, syntactically like TypeScript.
English |简体中文
Here are some variable declarations.
letflag:boolean=true;letcount:number=20;letcontent:string="Hello World";
Thanks to the type inference feature of StaticScript, we can write the above variable declaration as follows. They are exactly equivalent.
letflag=true;letcount=20;letcontent="Hello World";
The compiler of StaticScript cleverly deduced the type of the variable from the initial value.
In addition to usinglet
to declare variables, you can also useconst
to declare constants.
constname="StaticScript";constage=1;constdeveloping=true;
The difference betweenlet
andconst
is that constants declared withconst
cannot be modified.
You can use a wealth of operators to perform operations on variables, including arithmetic operations, bitwise operations, logical operations, relational operations, assignments, and string concatenation.
leta=1;letb=2;// add, subtract, multiply and divideletsum=a+b;letdiff=a-b;letproduct=a*b;letquotient=a/b;a=a<<1;// equivalent to `a <<= 1`b=b>>1;// equivalent to `b >>= 1`letyear="2020",month="08",day="06";letbirthday=year+"/"+month+"/"+day;
leta=1;letb=100;if(a<b){ss_println_string("b is bigger");}else{ss_println_string("b is not bigger");}letmax=a;if(a<b){max=b;}
StaticScript supports usingwhile
statement andfor
statement to do some repetitive things.
// Calculate the sum of all even numbers between [1, 100]letsum1=0;leti=1;while(i<=100){if(i%2==0){sum1+=i;}}// Calculate the sum of all integers between [1, 100]letsum2=0;for(leti=1;i<=100;i++){sum2+=i;}
StaticScript supports defining functions in the top level scope and using function in any scope.
functionadd(a:number,b:number):number{returna+b;}
The above function can omit the return type because StaticScript can deduce the return type through the expression of the return statement.
It is important to note that the parameter types of functions must be explicitly declared.
About
A new statically typed programming language, syntactically like TypeScript.
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Uh oh!
There was an error while loading.Please reload this page.