Fixing JavaScript Function Error: Passing Parameters to sum() Function

How to Pass Data to a JavaScript Function?? The following JavaScript function is broken. What will happen if you try to use it? “function sum() { return a + b; } “ sum(); // Reference Error: a is not defined When sum function is called, it throws a Reference Error: “a is not defined” Press enter or click to view image in full size If you call this function, you’re going to get a Reference Error which says, “a is not defined”. This makes sense — the sum function is using two values, a and b, but has no idea what they are. To fix it, we need to add a and b as parameters and pass two numbers as arguments. #javascript #function #programming #frontend #ui #ux #website

  • No alternative text description for this image

To view or add a comment, sign in

Explore content categories