Public
Edited
Jul 22, 2023
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
// add() takes in two arguments, both of which should be finite numbers, and returns their sum
function add(a, b) {
// Verify whether either of the two parameters are missing.
if(a === undefined || b === undefined)
throw Error("One or more parameters are missing from add()"); // Throw error
// Verify whether parameters are finite numbers by using Number.isFinite()
else if(Number.isFinite(a) && Number.isFinite(b))
return a + b; // Return sum
// Throw an error if both parameters are not numeric
else
throw Error("One or more parameters are not numeric"); // Throw error
}
Insert cell
Insert cell
add(23, 47);
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more