In the process of learning, there will always be a time before the place to be swallowed up, the following would be learned today to record the knowledge points to facilitate later viewing.
Data types in JavaScript
Simple (Basic) data type: number, String, Boolean, Undefined, Null
Complex (Reference) data type: Object, Array, Date, function, etc.
The following describes the differences between simple (basic) data types and complex (reference) data types:
Simple data type: Store values directly in the stack, as shown in the following figure
Complex data types: Store references in stacks, as shown below
After you understand how the two data types are stored, you can distinguish between the differences, and you can do the following exercises:
var a =10;
var b = A;
Q: When changing the value of a, the value of B changes
a=20;
Console.log (b);
var S1 = new Object ();
var s2 = S1;
Q: After changing the properties of the S1, S2 the same property changes
S1.name = "MH";
Console.log (s2.name); Mh
function F2 (arr)
{
arr = [9,8,7,6,5];//produces new object
arr[0]=-100;
}
var array = [1,2,4,7,5];
F2 (array);
Console.log (array[0]);// 1
Variable elevation, function declarations, and variable scopes in Javasript
First look at the following interview questions:
var num = ten;
Fun ();
function Fun ()
{
console.log (num);
var num =20;
}
I will answer directly to 10 before I learn JavaScript, and now learn the precompilation concept of the Var keyword and the concept of function declaration to know that the above code is equal to the following code:
var num;//global scope encounters var and function elevation
function fun () {
var num; Local do user encounter var elevation
console.log (num);
num =20;
}
num = ten;
Fun ();
Take another look at the following question:
Question: Why is the following error occurring?
//uncaught Typeerror:fnname is not a function
Console.log (fnname (1,2));
var fnname = function (a,b) {return
a + b;
}
The above code is equivalent to the following code:
var fnname;
Console.log (FnName (1,2));
FnName = function (a,b) {return
a + b;
}
You can see that the "uncaught typeerror:fnname is not a function" error is reported because the function is only promoted to Var on the right side of the equal sign.
To understand the scope of a variable, look at the following code:
F1 ();
Console.log (c);
Console.log (b);
Console.log (a);
Function F1 () {
var a = b = c =;
Console.log (c);
Console.log (b);
Console.log (a);
}
for Var a=b=c=20; This type of continuous assignment, in a local scope, only declares a, while the scope B and C are global scopes. Therefore, only a error in the global scope is "uncaught referenceerror:a are not defined".
Above this JS basic essay (rookie must SEE) is a small series to share all the content, hope to give you a reference, but also hope that we support the cloud-dwelling community.