JS Basics Flashcards
// What will the below code print out?
"use strict"; var a = 1; var b = {}; function foo(x, y) { x = 2; y.moo = 3; }
foo(a, b); console.log("a = " + a + "; b = " + JSON.stringify(b));
“a” is passed by value so updates to “a” in function foo will NOT be visible outside of the function foo and “b” being an object is passed by reference, so changes to properties of “b” in the function foo WILL be visible outside of the function foo.
a =1; b = {‘moo’:3}
// What will the below code print out? var asimsVar = 3; asimVar = 1; console.log(asimVar)
What is “use strict” and what does it do?
1
// What will the below code print out? "use strict"; var asimsVar = 3; asimVar = 1; console.log(asimVar);
What is “use strict” and what does it do?
It will throw an error
JavaScript Committee
TC39 on Github
How to get new features to work in old browswers
link to polyfill
What is strict mode?
Silent errors become
“use strict”; /// string
Strict mode eliminates some JavaScript silent errors by changing them to throw errors.
Strict mode prohibits some syntax likely to be defined in future versions of ECMAScript.
It prevents, or throws errors, when relatively “unsafe” actions are taken (such as gaining access to the global object)
Does JavaScript pass parameters by value or by reference?
privative types by value (copy)
objects by reference (pointer)
spread operator …
add one array to another one (three dots) ... var ar2 = [1,2,3, ar1]
rest operator
function login(...options) { // now have access to the parameter list like an array }
(three dots)