Why is this correct?


Well, the code runs fine. However I don't understand how the function can have nothing in the ( ) and works.

var count=0

var loop = function(){
		//Your code goes here!
		console.log("I'm looping!")



function can also have no arguments? it is fine, a function can have a argument:

var example = function(argument)

or not a argument:

var example = function(argument)

both is perfectly fine.


i always thought that (gonna use this current code as an example):

when we put loop(count), it will be used in function(count), and thus whatever the value count was, the value would be used in the resulting block of code of function() in the {} like this: while(count<3)


so i guess what i said is what will happen, but when there isnt any arguments, how does that work??


this code will both work with and without function. Well, simple? Function can manipulate global variable, so the global variable count will simply be used.


ok, then how do we know when to not have an argument in function?


oh wait i think i get your last statement, basically if there isnt anything betw the function(in here), the code in the block will use the global variable; if any global variable corresponds to the variable inside is it?


Sometimes arguments are really useful (when your function must do different things, you can pass arguments to determine this). There is no fixed rule for this

function always have the ability to access/manipulate global variable, the function parameter doesn't matter for this


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.