简体   繁体   English

将参数传递给带有变量的函数或在传递过程中进行修改

[英]Passing parameters to function with variable or modifying during passing

While passing parameter to function, there are two ways to pass and i'm not sure about which one is better?在将参数传递给函数时,有两种传递方式,我不确定哪种更好?

First one is:第一个是:

const foo = (bar) => bar;

number = 3.4567;
foo(number.toFixed(2));

Second one is:第二个是:

const foo = (bar) => bar;

number = 3.4567;
fixedNumber = number.toFixed(2);
foo(fixedNumber);

It is basically the same but in the second one you define a new variable for fixedNumber , thus making your code more readable for other developers.它基本上是相同的,但在第二个中,您为fixedNumber定义了一个新变量,从而使您的代码对其他开发人员更具可读性。

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

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