javascript Flashcards

(81 cards)

1
Q

how node treat module files

A

node never process the .js file directly, it wraps the module as a function and pass it to the chrome v8 engine

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

what’s the global object in node.js

A

global

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

what’s the global object in chrome

A

window; document

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

naming convention for class

A

ClassName

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

same folder path in require; parent folder path in require statement

A

same folder ./xxx(.js) parent folder ../xxx(.js)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

how to load a module

A

require(‘’)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

EMACscript 6 fancy string function is called?

A

Template String

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

the node.js built in packages

A

path os fs http events ( class: EventEmitter; methods: emit & on )

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Since events package provides an EventEmitter class (not an instance), what needs to be paid attention when working on the events?

A

the actual registering event and emit event action need to be based

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

what makes the function become the special constructor function inside a class defination

A

give the function name as ‘constructor’, then it will work with the new key word

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

what the class sytax sugar does

A
  • generating the function that 1) has the name of the class given and 2) coding block as the constructor method - attach all other attributes to the .prototype attribute of the function with class name
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

is most of the javascript keyword little cap

A

yes (new, function, class, cnst…)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

how to inheriant from another class when defining an class

A

using ‘extends’ keyword

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

singular module returning object

A

module.exports =

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

is module global?

A

it is actual a local variable that node.js passed into the wrapped function of the module

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

how to see the wrapped function of the module

A

set a syntax error in the very 1st line of a module like ‘var =;’ and then require it somewhere else

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

how to set async spin over certain time interval

A
  1. return a new Promise 2. Inside the promise, define another async function 3. Inside the function, if goal reached, then resolved; if not, use setTimeout to sell the call again. (*** The async function is within the ‘new Promise’, so whenever it resolved, the same promise instance resolved) 4. Call the async function manuallyafter defination
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

how to set parameter’s default value

A

constructor ({ keyId, secretKey, paper = true, bucketPct = 0.25 }) { … }

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

var scope situation

A

var only socpe to either functional scope or global scope (window or global object)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

let and const sope

A

they scope to the block scope (curly brackets)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

what is Hoisting in JS

A

variable can be used before the definition. (hoisting means moving all declarations to the top of the current scope

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

what is a primitive type in JS

A

it is not an object and has no methods

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

primitive types are immutable, how to approve it

A

you can not use an string method to alter e.g. toUpperCase the data itself (on the other side, the array method e.g. push can alter the array); the string method can then only manipulate the return value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

what is Symbol in JS

A

Symbols are often used to identify object properties.Often to avoid name clashing between properties, since no symbol is equal to another; No two symbols are the same ‘===’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
null vs undefined
null is an object; undefined is a type null can be assigned to variable; undefined appears when nothing assigned to variable
26
Map vs Object
27
JS 3 data structues
* Array, list of object * Map, key-value pair, simplified the historicially used Object * Set, unquie value of Array list
28
29
Date in JS
* number of milisecond since 1970 * new Date() - create a new Date object * Date.now() * Date.parse() - parse string date representation
30
Date - To get Date, Month and Year or Time
let [month, date, year] = new Date().toLocaleDateString("en-US").split("/") let [hour, minute, second] = new Date().toLocaleTimeString("en-US").split(/:| /)
31
Template String
`string text ${expression} string text`
32
Implicity Conversion
Implicit Coercion: Type conversion is done implicitly by JavaScript. * 12 + "" //Output is "12" as number 12 is converted to string "12" * "15" \* 2 //Output is 30 as string 15 is converted to number 15 * "15" - "11" //Output is 4 as both the strings are converted to number * undefined + 6 //Output is NaN as undefined could not be converted to number
33
Explicity Conversion
* Number("25") //Output is 25 as "25" string is converted to number 25 * String(25) //Output is "25" as 25 is converted to string "25" * Boolean(25) //Output is true *
34
Comparison Operations in JS
* loose compare: == (only compare value) * strict compare: === (compare value and type) * same-level compare: object.is()
35
spread operator vs. rest operator '...'
* Spread Syntax: [...iterableObj, '4', 'five', 6] * Rest Syntax: function f(a, b, ...theArgs) { // ... }
36
how to get array length
.length
37
using for loop through an array
38
using 'for ... of ..' to loop through the array
39
using 'for...in...' to loop through object
40
'while' loop
41
'while' loop with 'break'
42
'while' loop with 'continue'
43
loop using 'do.. while...'
44
what's the difference b/w 'do..while..' and 'while'
do...while... always run for the first time
45
'for.Each...' to loop through array
46
why it is better to always come to forEach when looping through array
it is more data object driven
47
Scope for 'this'
1. if 'this' defined inside a method, it always point to the object (not the method itself, but the object it belongs to); 2. if 'this' defined inside a function, it point to the window/global object 3.
48
what is the secon parameter of forEach function
thisArgs, value to be used as this inside the first param - the call back function
49
what is setter and getter in js
* let the method can be accessed like a true property from outside the object
50
does spread syntax has to be at last?
no, only rest syntax always has to be in the last position; spread syntax can be anywhere in side the parameter passing parenthesis
51
Destructuring Assignment Syntax
52
when the curly bracket can be ignore
when usiing 'if', 'for'...
53
constructor function vs. class
* constructor function is a regular function to be invoked with the 'new' keyword * class has the 'constructor' method; also to be instansized with 'new' keyword
54
thumb rule for determin the 'this' context: which one is correct 1. this is determined based upon where the function is called 2. this is determined based upon where the function is defined
1 is the correct answer
55
what's the difference of using .bind() vs. .call() / .apply()
using .bind() to invoke a function create a persistent binding of this context that always connect to the function. so we can not eyeball it when just reading the code and always need to be searched the binding. This probably should not be recommended However, the .bind() can be used to fix the callback method missing this context issue
56
5 binding types tips 1. implicit binding 2. Explicit binding 3. new Binding 4. Default Binding 5. Callback Binding
1. implicit binding - object.func() - bind to whatever left to the dot 2. Explicit binding - .call(); .apply(); .bind(); forEach()... 3. new Binding - new func() 4. Default Binding - func() - bind to global object 5. Callback Binding - loosing the implicit binding
57
how to pass parameters to callback function when using setTimeOut or setTimeInterval
use the 3rd parameter: setTimeOut( callBackFunc, , args )
58
iterator signature method and what's its returning value
* .next() * { value: xxx, done: true/false }
59
generator function syntax
function\* xxx () { yield }
60
inside generator function, how to delegate to another deeper level generator
yield\* generatorFunc() The yield\* expression iterates over the operand and yields each value returned by it.
61
yield as expression
achieving the goal for 2 way data exchange
62
63
Accessing the await-ed value inline (JS)?
async
64
how to inline invoke (async) function using **grouping operator ( )**
The **grouping operator ( )** controls the precedence of evaluation in expressions.
65
npm package.json vs. package-lock.json
https://stackoverflow.com/questions/45052520/do-i-need-both-package-lock-json-and-package-json
66
node.js working with json file
package fs function JSON.parse()
67
deconstructing Assignment
[a, b, ...rest] = [10, 20, 30, 40, 50]; const x = [1, 2, 3, 4, 5]; const [y, z] = x;
68
what happens to the created object if adding attributes to the construction function's .prototype object
The attribute will NOT be added directly to the created object, but will be attached to its \_\_proto\_\_ chain.
69
node js package for database access and management
sequelize
70
what is following statement: ## Footnote $(function () { // do stuff });
71
.then behavior depends on handler function
[https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global\_Objects/Promise/then](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then)
72
what is the term for Node js implementing the async behaviori
Non-blocking I/O
73
which module helps fs package implement the sync file reading function - fs.readFileSync()
[https://stackoverflow.com/questions/17336779/if-nodejs-uses-non-blocking-io-how-is-fs-readfilesync-implemented](https://stackoverflow.com/questions/17336779/if-nodejs-uses-non-blocking-io-how-is-fs-readfilesync-implemented) bindings module
74
when declaring class, how to define a method attribute
the function keyword can be ignored, the same applies to async function - only keep async following by the function name is fine
75
When passing callback function to setTimeOut, what if the target callback function is a method of an instance
Do not pass the function directly as when the callback function invoked, the scope changes. put the callback function with 'this.' inside another wrapper function and pass the wrapper function as the parameter to setTimeOut.
76
use destructuring in JavaScript function arguments
yes, this is a bit odd but it makes sense. And the deconstructed arguments can be used directly inside the function (even though it looks like a attribute inside a parameter object but it doesn't need a top level object to be referred to)
77
using switch...case... statement: 1. what is the other option keyword 2. must using break 3. Special signal to use
1. default 2. Yes 3. :
78
does await works in .forEach? if not, what is the walk around
No, try to use for... loop
79
Given the non-blocking I/O design in JS, what are the issue presents by this architecture? What are the values brought by Callback Function, Promises, Async Function in different level.
* how to resume the process once the I/O finished - Callback * having a clear status of the I/O process - Promise's status * In case where a blocking I/O is desired - use promise.then() or await * Disadvange of using callback or promise.then() - callback hell and promise hell
80
why in node.js, we should always use 'module.exports = ' rather than ' exports = ' when exporting single object
Because assign value to 'exports' directly will change the referenced object it is pointing to but the node js will only export to the object point by module.exports. (They were originally pointing to the same object) [https://stackoverflow.com/questions/7137397/module-exports-vs-exports-in-node-js/26451885#26451885](https://stackoverflow.com/questions/7137397/module-exports-vs-exports-in-node-js/26451885#26451885)
81
what's the differece b/w Reset Parameters and The argument object
* The **arguments object is not a real array**, while **rest parameters are Array** instances, meaning methods like **sort, map, forEach or pop** can be applied on it directly; * The arguments object has additional functionality specific to itself (like the callee property). * The **...restParam** bundles all the extra parameters into a single array, therefore it does **not contain any named argument defined before the ...restParam**. Whereas the arguments object contains all of the parameters -- including all of the stuff in the ...restParam -- unbundled.