5. Practice Makes Perfect: Why var loop = function()


#1



https://www.codecademy.com/courses/javascript-beginner-en-ASGIv/1/1?curriculum_id=506324b3a7dffd00020bf661#

More of a question.. Why do we need var loop = function() in the following code:

Not understanding why that is relevant. Is there a way to write the code without that line of code?

Any insight is appreciated. Thanks!


var count = 0;

var loop = function(){
	while(count < 3){
	console.log("I'm looping!");
	count++;
	}
};
loop();


#2

Yes, your code would still work without that line. writing the code with this line var loop = function() makes the code reusable. Meaning it can be called multiple times. :slight_smile: