2014-02-10 31 views
-1
var MyCountry = "trolling"; 
console.log(MyCountry).length; 
console.log(MyCountry).substring(0, 3) 

這是錯誤消息我得到:基本的JavaScript我不明白

TypeError: 'undefined' is not an object (evaluating 'console.log(MyCountry).length')

+0

從曳?優雅。 – user2864740

回答

1

這是你想要的。兩次都過快關閉console.log()。

var MyCountry = "trolling"; 
console.log(MyCountry.length); 
console.log(MyCountry.substring(0, 3)); 
2

你對console.log()結果,這始終是undefined.length.substring。將它們放在MyCountry之內。

0

console.log()返回undefined,所以你打電話.length未定義。

如果你想登錄MyCountry的長度做console.log(MyCountry.length)

此外,console.log(MyCountry.substring(0, 3))