In general, a playwright assertion like expect does not return a boolean value. Instead, it is used to check whether a given value matches some expected condition, and if not, it will throw an error. In the example you provided, expect(true).toBeTruthy() will simply check whether the value true is truthy (i.e., evaluates to true when converted to a boolean) and will throw an error if it is not.
As for why the variable bar is undefined, it is because you are not assigning it any value. In the line let bar = await expect(true).toBeTruthy();, the await keyword is used to wait for the expect statement to complete before continuing with the rest of the code. Since expect does not return a value, bar will remain undefined.
If you want to store the result of an expect statement in a variable, you can use a try/catch block to catch any errors that are thrown by the assertion. For example:
let bar;
try {
await expect(true).toBeTruthy();
bar = true;
} catch (err) {
bar = false;
}
In this code, if the expect statement passes (i.e., the value true is truthy), then bar will be assigned the value true. If the expect statement fails (i.e., the value true is not truthy), then bar will be assigned the value false