Skip to content

Latest commit

 

History

History
100 lines (78 loc) · 4.36 KB

variable-assignments.md

File metadata and controls

100 lines (78 loc) · 4.36 KB

literals

Open in playground

export const main = asl.deploy.asStateMachine(async () => 
 {
  let str = "string";
  let num = 42;
  let bool = true || false;
  let object = { str, num, bool };
  let object2 = { str: "string", num: 33, inner: object };
  let arrayOfNumbers = [1, 2, 3, 4, 5];
  let arrayOfObjects = [{ left: 1, right: 2 }, { left: 3, right: 4 }, { left: 5, right: 6 }];
  return { arrayOfNumbers, arrayOfObjects, object2 };
});

array with identifiers

Open in playground

export const main = asl.deploy.asStateMachine(async () => 
 {
  let str = "string";
  let num = 42;
  let bool = true || false;
  let object = { str, num, bool };
  let array = [str, num, bool, object];
  return array;
});

unassigned variable

Open in playground

export const main = asl.deploy.asStateMachine(async () => 
 {
  let arr: [];
  let two: string;
  return two;
});

assignment to undefined

Open in playground

export const main = asl.deploy.asStateMachine(async () => 
 {
  let _undefined = undefined;
});

assignment to null

Open in playground

export const main = asl.deploy.asStateMachine(async () => 
 {
  let _null = null;
});

array indexer

Open in playground

export const main = asl.deploy.asStateMachine(async () => 
 {
  let arr = [1, 2, 3, 4, 5]
  let two = arr[1];
  arr[1] = arr[3];
  arr[3] = two;
  return arr; //returns [1, 4, 3, 2, 5] 
});

functions

Open in playground

export const main = asl.deploy.asStateMachine(async () => 
 {
  let str = asl.states.format("hello {}", "world")
  let num = asl.states.format("answer is {}", 42);
  let combined = asl.states.format("1: {}\n 2: {}", str, num);
  let arr = asl.states.array(str, num, combined);
  return arr;
});