[英]React error - ./src/App.js Line 16: Parsing error: Unexpected token
i tried a tutorial from their site and i encountered this error and i dont know what is wrong. 我从他们的站点尝试了一个教程,遇到了这个错误,我不知道出了什么问题。 This is the code:
这是代码:
function formatName(user) {
return user.firstName + ' ' + user.lastName; //this is line 16
}
const user = {
firstName: 'Ciofliceanu';
lastName: 'Serban';
};
const element = <h1>Hello, {formatName(user)}</h1>;
ReactDOM.render(element, document.getElementById('root'));
I expect the output to be Hello, Ciofliceanu Serban but the output is: ./src/App.js Line 16: Parsing error: Unexpected token 我期望输出为Hello,Ciofliceanu Serban,但输出为:./src/App.js第16行:解析错误:意外的令牌
The error is most likely really happening at definition of user
as this is not a proper object literal: 该错误很可能确实发生在
user
定义上,因为这不是正确的对象文字:
const user = {
firstName: 'Ciofliceanu';
lastName: 'Serban';
};
Try replacing the ;
尝试更换
;
with ,
: 与
,
:
const user = {
firstName: 'Ciofliceanu',
lastName: 'Serban'
};
Hopefully that helps! 希望有帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.