undefined vs 'undefined'
if (id !== 'undefined') { console.log("admin post movie id: "+ id); console.log("admin post movie doctor: "+ movieObj.doctor); Movie.findById(id, function(err, movie){ if (err) { console.log(err); } _movie = _.extend(movie, movieObj); _movie.save(function(err, movie){ if (err) { console.log(err); } res.redirect('/movie/' + movie._id); }) }); } else { _movie = new Movie({ doctor: movieObj.doctor, title: movieObj.title, country: movieObj.country, language: movieObj.language, year: movieObj.year, poster: movieObj.poster, summary: movieObj.summary, flash: movieObj.flash }); _movie.save(function(err, movie){ console.log("new submit movie "+movie); if (err) { console.log(err); } res.redirect('/movie/' + movie._id); }) }
@Scott老师的(id !== 'undefined')是如何可以正常工作的呢?我这边儿使用这个代码总是会出错,正确的应该是(id !== undefined),在JavaScript里面undefined和'undefined'是两个完全不一样的概念。