getting SyntaxError: Invalid shorthand property initializer (This isn't spam and i don't have other people mistakes who posted the same question)
getting SyntaxError: Invalid shorthand property initializer (This isn't spam and i don't have other people mistakes who posted the same question)
刚开始学js。
我 运行 这个异常: SyntaxError: Invalid shorthand 属性 initializer
这是我的代码:
const movie = {
title: 'a',
releaseYear = 2018,
rating: 4.5,
director: 'b'
};
showProperties(movie);
function showProperties(obj){
for (let key in obj){
if (typeof obj[key] === 'string')
console.log(key, obj[key]);
}
}
这段代码有什么问题?我检查了其他在他们的 js 代码中出现此错误的人,但我没有 none 他们的错误。
我该怎么办?
谢谢。
正确的代码:
const 电影 = {
标题:'a',
发布年份:2018,
评分:4.5,
导演:'b'
};
嗨
你必须在第 3 行使用 : 而不是 =。
这就是它发生的原因
刚开始学js。 我 运行 这个异常: SyntaxError: Invalid shorthand 属性 initializer
这是我的代码:
const movie = {
title: 'a',
releaseYear = 2018,
rating: 4.5,
director: 'b'
};
showProperties(movie);
function showProperties(obj){
for (let key in obj){
if (typeof obj[key] === 'string')
console.log(key, obj[key]);
}
}
这段代码有什么问题?我检查了其他在他们的 js 代码中出现此错误的人,但我没有 none 他们的错误。
我该怎么办?
谢谢。
正确的代码:
const 电影 = { 标题:'a', 发布年份:2018, 评分:4.5, 导演:'b' };
嗨 你必须在第 3 行使用 : 而不是 =。 这就是它发生的原因