Variables, Scope, and Memory Flashcards
What are primitive values?
Simple atomic pieces of data
What are reference values?
Objects that may be made up of multiple values
What are the 5 primitive types?
Undefined, Null, Boolean, Number, String
What is an example of a reference type in JavaScript?
an Object. When you manipulate an object, you’re really working on a reference to that object rather than the actual object.
Can you add properties to primitive values?
No. Only to reference values.
What is the value of num2?
var num1 = 5; var num2 = num1; var num1 = 6;
5
When a reference value is assigned to a variable what is the actual value of the variable?
A pointer to an object stored on the heap
var obj1 = new Object(); var obj2 = obj1; obj1.name = "Scott"
What is the value of obj2.name?
“Scott”
What does passed by value mean?
a value is copied from one variable to another.
What does passed by reference mean?
the location of the value in the memory is passed from one variable to another (Objects)
How are function arguments passed in ECMAScript?
They are passed by value. Function arguments should be considered nothing more than local variables within functions.
What is the instanceof operator used for and what does the syntax look like?
it is used to determine what type of object an object is.
result = variable instanceof constructor
What does this return?
person instanceof Object
true (if person is an object.)
typeof(obj) => true
If you want more information about this object what operator can you use?
obj instanceof Object => true
obj instanceof Array => false
What is the global execution context?
The outermost context. It changes depending on the host environment but in web browsers the global context is the window object.