From the course: Computer Science Principles Lab: JavaScript

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Return values from functions

Return values from functions - JavaScript Tutorial

From the course: Computer Science Principles Lab: JavaScript

Start my 1-month free trial

Return values from functions

- [Instructor] In addition to accepting values and functions, you can return values from functions. This allows you to use functions like any other variable because when you run it, it returns a value. You already know of two ways to assign values to a variable. The first is to assign a defined value, like the number five. This is called a literal. The other way is to use math, or some other function, to change a value, like using addition or subtraction. This is called an evaluation. The third is to use a function, but that function needs to return a value. If we open up the code for this lesson, we'll see that we have a variable that holds a subtotal and we output that to the console log. It doesn't do that much but what we need to do is add a way to calculate the tax. Since tax could be different based on location, we should create a new function to calculate the tax and use a function parameter to change what the tax rate should be. We can create a new function to do exactly that.…

Contents