各位版上的大神们好,想请问各位:
let age = 27;
age.toString();
if (age===27) {
console.log("number");
} else if (age==="27") {
console.log("string");
} else {
console.log("I don't know.");
}
这个例子中,结果会是‘number’,因为 age 是 number,只有 age.toString 是 string 对吗?
第二个例子:
let friends = ["John", "Sandy", "Alex", "Jim", "Greg"];
let friends = ["John", "Sandy", "Alex", "Jim", "Greg"];
friends.push("Harry");
console.log(friends);
这个例子中,结果会是["John", "Sandy", "Alex", "Jim", "Greg", "Harry"]
但,为什么第一个例子中 age 使用了 .toString() 后,‘age’ 本身并没有变成 string;但在第二个例子中,friends 使用了 .push("Harry") 后,‘friends’本身却改变了?
感谢各位!