-
Notifications
You must be signed in to change notification settings - Fork 0
Statements and expressions
GoogleFeud edited this page Nov 19, 2020
·
2 revisions
Mafiascript has statements and expressions. This page explains the differences between the two.
Statements are a piece of code that do not return anything and control the flow of the program.
if (expression) {
//body
} else if (exp) {} else if (exp) {} else {};
if (expression) expression
else expression;
loop (before, check, after) {
//body
}
Where before
can be:
- A declaration statement
- Any expression
Where check
can be:
- Any expression
Where after
can be:
- Any expression
before
and after
are optional. A loop can also have just a check
:
loop (check) { ... };
loop (check, after) { ... };
loop (before, check, after) { ... };
const something = expression;
let somethingElse = expression;
somethingElse = expression;
somethingElse += expression;
somethingElse -= expression;
somethingElse *= expression;
somethingElse /= expression;
return expression;
return;
Everything else that's not a statement
is an expression. This includes:
- Primitive values (string, number, boolean, null)
- Array and object literals
const arr = [1, 2, 3];
const obj = {
"a": expression
};
- Functions
const func = (param) => {
//body
}
- Binary operations (
+
,-
,*
,/
) - Unary operations (
!
,++
,--
) - And / Or (
&&
,||
) - Function calls
func(15);
- Property accessors
arr[0];
obj.a;
obj["a"].toString();
- Typeof keyword
typeof obj.a;
- Ternery
expression ? ifTrue:ifFalse;