简体   繁体   English

Javascript:参数是变量还是常量?

[英]Javascript: Are arguments variables or constants?

Let me show you a very simple example: 让我向您展示一个非常简单的示例:

function abc(x, y, z){
 x = x.toLowerCase();
 return x;
}

Can I change the value of arguments of a function? 我可以更改函数自变量的值吗?

The arguments are variables 参数是variables

 function foo(x){ x = x.toLowerCase(); return x; } console.log(foo("ABC")) 

If they were constants... you wouldn't be able to set its value in the first place rendering the parameters useless 如果它们是常量...您将无法首先设置其值,从而导致参数无用

Yes you can, here is how to. 是的,您可以,这是操作方法。

 function abc(x, y, z){ x = x.toLowerCase(); return x; } abc = function(x = 'totally new way') { return x; } alert(abc()); 

Try This: 尝试这个:

 function abc(x, y, z) { return x.toLowerCase() } console.log( abc('HeLLo') ); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM