JavaScript函数作为参数错误-SyntaxError:意外标记{

JavaScript函数作为参数错误-SyntaxError:意外标记{,javascript,Javascript,我是Javascript新手。现在我正在学习函数。我不知道为什么下面的代码会产生错误 var myFunc= function() { return 5; }; otherFunc(myFunc){ alert(myFunc); }; SyntaxError: Unexpected token { 我在Google Chrome的控制台中编写了这两个函数 var otherFunc= function(myFunc){ alert(myFunc); } 或 这就是js中函数的定义方式 o

我是Javascript新手。现在我正在学习函数。我不知道为什么下面的代码会产生错误

var myFunc= function()
{
return 5;
};

otherFunc(myFunc){
alert(myFunc);
};

SyntaxError: Unexpected token {
我在Google Chrome的控制台中编写了这两个函数

var otherFunc= function(myFunc){
alert(myFunc);
}

这就是js中函数的定义方式


otherFunc(myFunc)
是我们调用函数的方式,你在它后面放了一个
{
,所以js运行时说意外的标记
{

第二个函数不是函数,你期待什么呢?第二个“函数”要成为函数,它需要在它前面写一个单词function。
function otherFunc(myFunc){/*…*/}
谢谢大家。这很简单。:D
function otherfunc(myFunc){
alert(myFunc);
}