I’ve changed your post to the p5.js forum category then.
p5js is a diff. flavor beast.
Indeed, none of its API is available until either it finds out that setup() or draw() is in the global context (window) or we manually instantiate class p5: new p5;
new p5; // prematurely instantiate class p5. ;-)
const SQRT_3 = sqrt(3); // we can access p5's sqrt() method outside functions!
function setup() {
print(SQRT_3);
}
For cos() & sin() and similar, we can always directly rely on the class Math:
const SQRT_3 = Math.sqrt(3); // Directly accessing JS' Math method sqrt().
function setup() {
print(SQRT_3);
}