Serenity Operating System
1try {
2 let getNumber = () => 42;
3 assert(getNumber() === 42);
4
5 let add = (a, b) => a + b;
6 assert(add(2, 3) === 5);
7
8 const addBlock = (a, b) => {
9 let res = a + b;
10 return res;
11 };
12 assert(addBlock(5, 4) === 9);
13
14 const makeObject = (a, b) => ({ a, b });
15 const obj = makeObject(33, 44);
16 assert(typeof obj === "object");
17 assert(obj.a === 33);
18 assert(obj.b === 44);
19
20 let returnUndefined = () => {};
21 assert(typeof returnUndefined() === "undefined");
22
23 const makeArray = (a, b) => [a, b];
24 const array = makeArray("3", { foo: 4 });
25 assert(array[0] === "3");
26 assert(array[1].foo === 4);
27
28 let square = x => x * x;
29 assert(square(3) === 9);
30
31 let squareBlock = x => {
32 return x * x;
33 };
34 assert(squareBlock(4) === 16);
35
36 const message = (who => "Hello " + who)("friends!");
37 assert(message === "Hello friends!");
38
39 const sum = ((x, y, z) => x + y + z)(1, 2, 3);
40 assert(sum === 6);
41
42 const product = ((x, y, z) => {
43 let res = x * y * z;
44 return res;
45 })(5, 4, 2);
46 assert(product === 40);
47
48 const half = (x => {
49 return x / 2;
50 })(10);
51 assert(half === 5);
52
53 console.log("PASS");
54} catch {
55 console.log("FAIL");
56}