在这里,我不明白当我var在函数中使用 before 变量时会发生什么,它给了我不同的输出,并且不使用var也得到了不同的输出
这是一段代码,您可以轻松地弄清楚发生了什么
function value() {
var m = 8; //here i am using var as a datatype
console.log(m)
}
m = 7
console.log(m);
value();
console.log(m);Run Code Online (Sandbox Code Playgroud)
而且当我删除 var 或不使用值函数中的任何数据类型时,我得到了不同的输出,这里是一个代码
function value() {
m = 8; //here i am not using var as a datatype
console.log(m)
}
m = 7
console.log(m);
value();
console.log(m);Run Code Online (Sandbox Code Playgroud)
谁能告诉我发生了什么事吗?谢谢您的宝贵时间
我将深入研究 javascript 对象操作。这里我的问题是两者之间有什么不同const me = Object.create(person);,const me = person;这两个操作都给了我一个更小的输出。我的意思是它引用对象到新变量me。
const person = {
isHuman: false,
printIntroduction: function() {
console.log(`My name is ${this.name}. Am I human? ${this.isHuman}`);
}
};
const me = Object.create(person);
me.name = 'Matthew';
me.isHuman = true;
me.printIntroduction();
const me2 = person;
me.name = 'Manan';
me.isHuman = false;
me.printIntroduction();Run Code Online (Sandbox Code Playgroud)
在上面的代码中,我包含了直接操作assignment和使用分配Object.create();。这里两个变量都引用了 person 对象,但是它们之间有什么不同呢?有人能给我解释一下吗?这个问题可能以前被问过,但我找不到正确的解释。简单的解释将不胜感激:-)。