How to return a value outside its function?

How to return a value outside its function?
0.0 0

#1
let array = [];

function getCheckboxes(checkbox) {
	let addRandomCheckbox = new RandomAdd(checkbox);
	array.push(addRandomCheckbox);
	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.


#2

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.


#3

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.


#4

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