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')
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')
這是你想要的。兩次都過快關閉console.log()。
var MyCountry = "trolling";
console.log(MyCountry.length);
console.log(MyCountry.substring(0, 3));
你對console.log()
結果,這始終是undefined
把.length
和.substring
。將它們放在MyCountry
之內。
console.log()
返回undefined,所以你打電話.length
未定義。
如果你想登錄MyCountry的長度做console.log(MyCountry.length)
此外,console.log(MyCountry.substring(0, 3))
從曳?優雅。 – user2864740