JS Basics (HR) Flashcards
what is the type of “hi”
string literal
what type is - true - and what cn it represent?
boolean. represents opposing ideas, such as on vs off, positive vs negative, present vs absent, or truth vs falsehood
what is the type - underfined - and what does it represent?
undefined value represents an unknown or undetermined state. Will receive this value, when someone or some system is trying to indicate to you that the info you’re inquired about could not be found.
what is the type of 3
number literal
what do you need in order to make calculations
Operators. Operators are things like plus, known as the addition operator, and they imply that some work should be done on the values around them. Research operator precedence if i want to learn more about order of operations
What are expressions?
A set of literals, variables and operators intended to tell your computer how to take one small step forward in a larger computation. When processes at run time, every expression will have a result value. It will “evaluate to”
where to go for understanding how my JS interpreter will process my code, and it what order.
http://jsparse.meteor.com
what is this type of statement? log((3+1)* 2);
expression statement. the semicolon has effect of discarding the result value of the full, compound expression occupying the entire line, allowing the interpret to proceed with clean slate
how would you describe this? var result = (3+1) * 2;
Variable declaration statement.
describe a variable
storing a previously-computed value by naming it with a variable. A variable can be thought of as a “label” or “alias” that points to some value stored
What will the var other log to the console in this scenario? var result = (3+1)*2; log(result); var other = result; result = 5; console.log(other);
- This is because other will store the original value, since our new (overwriting) assignment operation told teh interpreter to make result point to something different, but it did not tell the interpreter to make other point to something different.
what is it called to define an object like this: var myObj = {};
Object literal
In an object, what is the combination of one key and one value called?
property
What does a failed property lookup evaluate to?
undefined
when accessing accessing or assigning properties with bracket access
the value, if not already a string, gets stringified before lookup
True/False -> you can do a for/in loop on arrays
True
True/False -> arrays can have non-integer keys
True, but they do not count towards their “length”
What are “enumerable” properties of an array
they are certain built-in properties that Javascript knows you don’t want to iterate over in a for (with semicolons) loop for example
are functions, objects?
yes, they can store properties just like any other object. you can’t run function.length on them though, as that is reserved for Arrays. you could iterate through them only with for/in loops though
what is it called to activate whatever behavior that function is capable of?
to Invoke.
how to you make a function run?
you put brackets () at the end of it. this will make what is inside the {}, known as the body, run.
what is the work done to the environment around it (such as logging a message to the console) called?
a Side Effect
what always returns if there is no “return” statement in a function?
undefined
will the lines inside the {} run automatically?
No, only when the function is invoked with (), will it run. It will never run, not even once, until it is invoked with a ()
what is “hi” considered to be when calling the function fun(“hi”);
the Argument
talk about the arguments object in a function
it is a special keyword called ‘arguments.’ instead of being assigned to a value with the assignment operator, the arguments keyword just automatically holds a brand new array every time you invoke the contain function. the elements coin the array will be the arguments that got passed during the current invocation
how to create an parameter via the arguments object?
NOT LIKE THIS:
var fun = function(input){
console.log(input.toUpperCase());
}
BUT LIKE THIS: var fun = function(){ var input = arguments[0]; console.log(input.toUpperCase()); }
what happens when you refer to a parameter by its name, even though no corresponding argument was passed in during the invocation? var fun = function(input){ console.log(input.toUpperCase()); }
fun(); //logs what??
undefined
what will happen if you try to refer to arguments from within a nested function?
that reference to arguments will refer to an array of values that were passed in to the inner function
can you use the same variable for parameters in nested functions?
Yes, you can use the same variable names
setTimeout, is a native function that takes two parameters - (myFunk, time to run myFunk). how would you run myFunk, which takes a parameter? (Note: setTimeout does not allow for adding a parameter to myFunk
Wrap myFunk in an anonymous function, that passes in a parameter into myFunk like this:
setTimeout(function(){
myFunk(‘hi’);
}, 1000);
Are you allowed to assign properties to an Object that is set to “null” or “undefined”?
Nope. it will throw an error
what are immutable values?
It means you can’t modify them (by adding properties to them). Immutable objects include: booleans, Strings, and Numbers
what is a method?
an object’s property that is pointing to a function