Javescript关于功能的基本问题

Javescript关于功能的基本问题

本文介绍了Javescript关于功能的基本问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

function formatAmount() {
	return "$" + amount.toFixed( 2 );
}

var amount = 99.99;
var kk = 11.11;

amount = formatAmount();
kk = formatAmount(); //TypeError: amount.toFixed is not a function (line 2 in function formatAmount)

console.log(amount); //"$99.99"





我的尝试:



我有两个问题:



1.

为什么分配函数 formatAmount()金额但不能这样做 kk



2.

如果我将函数 formatAmount()分配给金额,那么金额的价值不再是99.99,对吗?那么 amount.toFixed(2) console.log(金额)中的输出仍为99.99?



What I have tried:

I have two questions:

1.
Why it is OK to assign function formatAmount() to amount but not OK to do so to kk?

2.
If I assign function formatAmount() to amount, then the value of amount is no longer 99.99, right? Then why the output of amount.toFixed( 2 ) in console.log(amount) is still 99.99?

推荐答案






我尝试了什么:



我有两个问题:



1. br />
为什么可以将函数 formatAmount()分配给金额但是不能这样做到 kk



2.

如果我指定函数 formatAmount()金额,那么金额的值不再是99.99 ,对吗?那么为什么 console.log(金额) amount.toFixed(2)的输出仍为99.9 9?



What I have tried:

I have two questions:

1.
Why it is OK to assign function formatAmount() to amount but not OK to do so to kk?

2.
If I assign function formatAmount() to amount, then the value of amount is no longer 99.99, right? Then why the output of amount.toFixed( 2 ) in console.log(amount) is still 99.99?


function formatAmount() {
	return "


这篇关于Javescript关于功能的基本问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 09:16