How to return a value outside its function?

How to return a value outside its function?
0.0 0

let array = [];

function getCheckboxes(checkbox) {
	let addRandomCheckbox = new RandomAdd(checkbox);
	return array;

let getValue = getCheckboxes();
console.log(getValue); // returns nothing

This returns nothing…but if I do console.log(array) inside the function; there are some value inside the array.


You have a parameter named checkbox for your getCheckboxes function, but when you call it with the following, you are not passing in a value.

let getValue = getCheckboxes();

Inside getCheckboxes, when no value is passed into it, then checkbox has the value undefined. I do not know what your RandomAdd function returns, but it is being passed the value undefined.


To add to randall’s answer…

The reason arra has a value when you print it is because it is a global variable so it is getting modified inside getCheckBoxes.


You were right…was a small mistake from my side.