Member-only story

JavaScript Basics: How to return a value from a function in Vanilla JavaScript

RayRay
2 min readOct 31, 2017

--

This time I want to talk what a return statement does and how you can return a value from a function in Vanilla JavaScript.

If you don’t like to watch a video, then scroll down for reading (almost) everything I said in the video.

Let’s start with creating a simple multiply function in Vanilla JavaScript.

function getMultiply(numberParam) {
console.log('Multiply', numberParam * numberParam);
}

We can call it with:

getMultiply(7);

So now this function will multiply the number 7. But we can’t do anything with the outcome of it.

Return a value from the function

Let’s bring in the return statement.

function getMultiply(numberParam) {
return numberParam * numberParam;
}

Now we have to call the function in the console.log to see the outcome.

console.log(getMultiply(7));

--

--

RayRay
RayRay

Written by RayRay

I’m a 🇳🇱 lead frontend developer who writes about WebDev | JavaScript | TypeScript | Vuejs | Web Components | Design Systems | NuxtJS | StencilJS | CSS

No responses yet

Write a response