Looks like JavaScript, feels like Ruby, and it is a script language fitting in C programmers.
This project is maintained by Kray-G
Logical AND operator is a shortcut operator,
and when using &&
and LHS is true
, the RHS will be evaluated.
var b = a && 10; // initializing 10 when a is true.
This can be also used with assignment operator as &&=
.
a &&= func(); // calling func and assign it to the variable of a, only when a is true.
function test(a) {
return a && 10;
}
System.println(test(0) ?? "null");
System.println(test(1) ?? "null");
System.println(test(null) ?? "null");
0
10
null
var id;
class A() { @id = id++; }
function test(a) {
a &&= new A();
return a ?? { id: 1 };
}
var a;
id = 10;
System.println((a = test(a)).id);
System.println((a = test(a)).id);
System.println((a = test(a)).id);
1
10
11