我正在尝试使用节点js创建一个对象,但由于某种原因它不接受/记住我正在使用的代码:
users-mbp:~ user$ node
> var author = { firstName: Alex, lastName: Snail, "age: 28", favoritefood: ['lasagna', 'pizza']};
... author
... author.lastName
... c
> author.lastName
ReferenceError: author is not defined
> var author = { firstName: 'Alex', lastName: 'Snail', age: '28', favoriteFood { 'lasagna', 'pizza'}
... author
...
> author
ReferenceError: author is not defined
> author.lastName
ReferenceError: author is not defined
答案 0 :(得分:1)
您的错误引号错误的对象。正确的应该看起来像这样
var author = { firstName: 'Alex', lastName: 'Snail', age: '28', favoritefood: ['lasagna', 'pizza']}