What is the different between a parameter and a local variable?

前端 未结 4 865
你的背包
你的背包 2021-01-14 16:06

Apologies for what must seem like a very stupid question.

I\'m currently working through codecadamy, and this is throwing me off:

 var greet         


        
4条回答
  •  孤独总比滥情好
    2021-01-14 16:07

    The name in function(name) is a parameter. That is, it is used to pass data into the function. But, parameters are local variables. Assigning a value to name inside the function is a little strange though. I would assume you want to do something like this:

     var greeting = function(name) {         
         console.log(name); 
      };
    
      greeting("sausage");
    

    In this version of the code you are passing the value "sausage" into the function via the parameter name. This is useful because you can call the function many times and each time the function may print a different value depending on what you pass.

提交回复
热议问题