基本的Javascript我不懂

基本的Javascript我不懂,javascript,Javascript,这是我收到的错误消息: TypeError:“undefined”不是计算“console.logMyCountry.length”的对象 这就是你想要的。两次关闭console.log都太快 var MyCountry = "trolling"; console.log(MyCountry).length; console.log(MyCountry).substring(0, 3) 您正在将.length和.substring放在console.log的结果上,该结果始终未定义。将它们放在

这是我收到的错误消息:

TypeError:“undefined”不是计算“console.logMyCountry.length”的对象


这就是你想要的。两次关闭console.log都太快

var MyCountry = "trolling";
console.log(MyCountry).length;
console.log(MyCountry).substring(0, 3)
您正在将.length和.substring放在console.log的结果上,该结果始终未定义。将它们放在MyCountry中。

console.log返回undefined,因此您在undefined上调用.length

如果要记录MyCountry的长度,请执行console.logMyCountry.length


还有,从Trolling中选择console.logMyCountry.substring0,3

?上等的。
 var MyCountry = "trolling";
 console.log(MyCountry.length);
 console.log(MyCountry.substring(0, 3));