JavaScript Cert Flashcards

1
Q

Two main properties of an Error object thats passed as an arguement to catch in a try..catch?

A

Name
Message

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

Advantages of using Node.js ? (name three)

A

Asynchronous
Open Source
Non-Blocking

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

Valid Events when interacting with the browser?

A

-mousedown
-contextmenu
-keyup

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

describe “Modules”

A

-Modules can load each other
-special directives such as export and import can be used interchangeably
-a module is just a file that may contain a class or a library of functions for a specific purpose

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

correct syntax for accessing the property of an object in JavaScript?

A

The correct syntax for accessing the property of an object is:

  • objectName.property
  • objectName[“property”]
  • objectName[expression]
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

name some “JavaScript Frameworks”

A

Angular
Node.js
React

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

“Falsy” values:

A
  • 0
  • null
  • undefined
  • NaN
  • ”” or ‘’ (empty string)
  • false
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

valid data types in JavaScript:

A

-null
-undefined
-Object
-Symbol
-Number
-String
-BigInt
-Boolean

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

correct way to look for an element by its ID

A

document.getElementById(‘element’);

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

What are the 2 most important items in your npm package.json file if you plan to publish a package?

A

-Name
-Version

*these 2 together establish a unique identifier for your published package
*optional if not going to publish

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

3 Phases of Event Propagation in standard DOM

A

The standard DOM Events describes 3 phases of event propagation:

Capturing phase – the event goes down to the element. (value=1)
Target phase – the event reached the target element. (value=2)
Bubbling phase – the event bubbles up from the element. (value=3)

*there is also a None phase before capturing phase (not technically event propagation though) (value=0)

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

how do Events in the Target Phase trigger?

A

will trigger all listeners on an element in the order they were registered. Hence, the outer message will be displayed first, then the inner message.

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

What is a “Curried Function”?

A

“Curried Function”: Currying is a transform that makes f(a, b, c) callable as f(a)(b)(c). The advantage of currying is that it allows us to easily get the partials. For example, we might just want to call f(a) or f(a)(b), depending on our own needs.

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

If a function does not return a value, its value is equal to = __________

A

undefined

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

should you ever add a “new line” between return and the value? (Y/N)

A

No

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

jQuery libarary defines a function with ______?
Lodash library defines its main function with ______?

A

jQuery = “$”
Lodash = “_”

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

3 most popular “Testing Frameworks” used by JavaScript developers?

A

-Puppeteer
-Mocha
-Jasmine

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

Describe “Mocha” Testing Framework?

A

-feature rich JavaScript test framework running on Node.Js and in the browser
-makes Asynchronous testing simple and fun (synchronous testing also)

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

Describe “Puppeteer” Testing Framework?

A

Node library which provides a high-level API to control headless Chrome or Chromium over the DevTools Protocol

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

Describe “Jasmine” Testing Framework?

A

Behavior Driven development framework,
for testing JavaScript code

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

what is JUnit ?

A

unit testing framework for the** Java** (not JavaScript) programming language

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

describe a Callback function ?

A

a function passed into a function to be called later

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

by default, the sort() function sorts values as _____?

A

strings

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

How would we sort an array in ascending order?

A

arr.sort((a,b) => a - b );

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

How would we sort an array in descending order?

A

arr.sort((a,b) => b - a);

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

what are the different states for a promise?

A

-Pending : initial state, neither fulfilled or rejected
-Fulfilled : operation completed sucessfully
-Rejected : operation failed

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

3 ways to define a Function

A

-Declaration decl() *inherits current scope
-Expression expr() *inherits current scope
-Constructor cons() *inherits global scope

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

What is the nature of how Events happen in the DOM?

A

When an event happens on a element, it first runs the handlers on it, then on its parent, then all the way on up to other higher ancestors
–> ie Events Bubble up the event chain in DOM from innner elements to outer elements (children to parents)

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

the standard DOM Events describes 3 phases of event propagation:

A
  1. Capturing phase - the event goes down to the element
  2. Target phase - the event reached the target element
  3. Bubbling phase - the event bubbles up from the element
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
30
Q

What is DOM?

A

DOM - Document Object Model
–> a programming interface for HTML and XML documents
–>represents the page so that programs can change the document structure, style, and content
–>represents the page as nodes and objects (so languages like JavaScript can connect to page)

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

What is JavaScript Prototypical Inheritance?

A

-an in-memory object that defines properties and functions of other objects

*despite not having classes as defined by classical languages, JavaScript still has an inheritance model which is called Prototype Inheritance

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

JSON characteristics?

A

-data-interchange format
-JSON spec is based on object literal notation

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

Object Literal Notation characteristics?

A

-programming syntax

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

What do you call errors that happen in valid code?

A

runtime errors
(or) exceptions

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

What do you call errors that happen in invalid code (code that can’t be understood by the engine because it is syntactically wrong)?

A

parse-time errors

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

function types related to Promises ?

*think method handling architecture design

A

-then
-catch
-finally

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

A developer wants to use a module called DatePrettyPrint. This module exports one default function called printDate(). How can a developer import and use the printDate() function?

A

import printDate from ‘/path/DatePrettyPrint.js’;
printDate();

-simplest way to do it,
notice parenthesis when naming export function are not needed
-notice you can just call function after imported, instead of using dot notation to call from its class

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

how would you import all methods from a module called DatePrettyPrint

A

import * from ‘/path/DatePrettyPrint.js’;

note: think –> import *

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

what is correct way of creating a new instance of a object?
say example function is:

function Car(size,model){
this.size =size;
this.model=model;
}

A

new Car(‘large’,’Audi’);

note: New is the keyword

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

characteristics involving classes in JavaScript?

A

-there are two ways to define a class –> class declaration (or) class expression
-class expressions can be named or unnamed and the name given to a named class expression is local to the class’s body
-classes are the “special functions” which are primarily syntactical sugar over JavaScript existing prototype-based inheritance

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

splice() syntax

A

array.splice(start[, deleteCount[, item1[, item2[, …]]]])

For example:

arr.splice(1,3,4,5) means that at index 1, remove 3 items, then add items 4 and 5 into that index. With an array of [1,2,3], first it removes 3 items from index 1 (in this case, only 2 items because it reaches the end of array) . The array becomes [1] and then it adds the other 2 items to the array, which the array becomes [1,4,5].

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

describe the event DOMContentLoaded

A

event should be specified in the event listener as the DOMContentLoaded event will be fired when the DOM content is loaded, without waiting for images and stylesheets to finish loading.

document.addEventListener(“DOMContentLoaded”, function(){
// specify your code here
});

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

describe the event load

A

event is fired when the whole page has loaded, including all dependent resources such as stylesheets and images.

document.addEventListener(“load”, function(){
// specify your code here
});

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

3 main White Box testing techniques ?

A

-Path coverage
-Branch coverage
-Statement coverage

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

White Box testing vs Black Box testing ?

A

White Box: test the actual code, see and test the internal code
Black Box: test software from user’s point of view, perform testing without seeing the internal system code

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

Valid Cookie options:

A

path=/
domain=domain.com
expires= 19 Jan 2038 03:14:07 GMT (*gmt string)
max-age=3600
secure
samesite

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

when using functions as event handlers, which parameters can they accept?

A

only events

-only events can be passed into an event handler function

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

when using functions as event handlers, which parameters can they accept?

A

only events

-only events can be passed into an event handler function
-called Event Object, it is automatically passed to event handlers to provide extra features and information
-the target property of the event object is always a reference to the element that the event has just occurred upon

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

what does the Object.assign() method do

A

-copies all enumerable own properties from one or more source objects to a target object

–> basically copies the object, so it doesn’t reference the object in any way, so if a value changes in original object, your copied object does not change

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

what does the Object.entries() method do?

A

method returns an array of a given object’s own enumerable string-keyed property [key, value] pairs.

–>ex: let user = {
name: “John”,
age: 30
};

console.log( Object.entries(user) ); // what is the output?

answer: [ [“name”, “John”], [“age”, 30] ]

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

do arrow functions () => {} have access to this ?

A

no

-arrow functions are not bound to the object, so they do not have access to this

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

some main things to do to convert a non-async function with promise chaining to async function

A

-replace .then calls with await
-make the function async, ie put async keyword at beginning of function

*these are the main ideas

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

some main things to do to convert a non-async function with promise chaining to async function

A

-replace .then calls with await
-make the function async, ie put async keyword at beginning of function

*these are the main ideas

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

some main things to do to convert a non-async function with promise chaining to async function

A

-replace .then calls with await
-make the function async, ie put async keyword at beginning of function

*these are the main ideas

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

What is the use of breakpoint in JavaScript?

A

Breakpoints allow you to pause the code execution so that you can examine the current JavaScript values

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

2 ways to set the class for a DOM element

A

document.getElementById(“myId”).className = “myClass”;

document.getElementById(“myId”).setAttribute(“class”,”myClass”);

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

2 ways to set the class for a DOM element

A

document.getElementById(“myId”).className = “myClass”;

document.getElementById(“myId”).setAttribute(“class”,”myClass”);

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

facts about localStorage and sessionStorage

A

-both allow us to store key/value pairs in the browser
-both have their own storage limits (usually limited to 5mb(per domain))
-sessionStorage –> survives page refresh, but not browser restarts or tab closing/opening (exists only within the current browser tab)
-localStorage –> will not expire and it will remain after the browser restarts or even a OS reboot

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

valid ways of Initializing an array?

A

new Array()
Array()
[]

*remember that JavaScript is case-sensitive, so array() is not the same as Array() and will throw a ReferenceError message

56
Q

queue data structure for array

define these queue array functions:
push()
shift()
unshift()

A

-order collection of elements
-FIFO

push() –> appends a element to end
shift() –> gets 1st element and removes it, advancing queue, so 2nd element advances to new 1st element
unshift() –> add element to the beginning

*push() and unshift() can add multiple elements at once
*push() and pop() run fast, shift() and unshift() run slow

57
Q

stack data structure for array

define these stack array functions:
push()
pop()

A

-LIFO

push() –> add an element to the end
pop() –> takes an element from the end

58
Q

What are valid ways of accessing the defined car’s properties?

const car = {
color: ‘blue’,
‘the color’: ‘the blue’
}

A

car.color
car[‘color’]
let theColor = ‘the color’; car[’${theColor}’]

59
Q

Jest is a popular JavaScript testing framework, name some attributes/characteristics of it?

A

-maintained by Facebook
-highly preferred framework for applications based on React
-compatible with NodeJS, React, Angular, VueJS and other Babel based projects
-comes bundled with some interesting features like snapshot testing and a built-in tool for code coverage
-easy mocking
-free
-large community

59
Q

Jest is a popular JavaScript testing framework, name some attributes/characteristics of it?

A

-maintained by Facebook
-highly preferred framework for applications based on React
-compatible with NodeJS, React, Angular, VueJS and other Babel based projects
-comes bundled with some interesting features like snapshot testing and a built-in tool for code coverage
-easy mocking
-free
-large community

60
Q

when defining the package version, what are the rules for semantic versioning and its version numbers?

A

Tilde symbol ~ includes everything greater than a particular version in the same minor range.
–>~1.0.0 allows versions 1.0.0, 1.0.1, 1.0.2, and so on

Carat symbol ^ includes everything greater than a particular version in the same major range.
–>^1.0.0 allows versions 1.0.0, 1.0.1, 1.0.2, 1.1.0, 1.2.3 and so on.

61
Q

Map methods:

also what is a Map?

A

new Map() – creates the map.
map.set(key, value) – stores the value by the key.
map.get(key)– returns the value by the key, undefined if key doesn’t exist in map.
map.has(key) – returns true if the key exists, false otherwise.
map.delete(key) – removes the element (the key/value pair) by the key.
map.clear() – removes everything from the map.
map.size – returns the current element count.

*Map –> collection of keyed data items (just like an object)

62
Q

Set methods:

also what is a Set?

A

new Set([iterable]) – creates the set, and if an iterable object is provided (usually an array), copies values from it into the set.
set.add(value) – adds a value, returns the set itself.
set.delete(value) – removes the value, returns true if value existed at the moment of the call, otherwise false.
set.has(value) – returns true if the value exists in the set, otherwise false.
set.clear() – removes everything from the set.
set.size – is the elements count.

*Set –> special type collection - “set of values” (without keys)

63
Q

Numeric Conversions:

for values like:
-undefined
-null
-true/false
-string
-error

A

Value Becomes…

undefined –> NaN
null –> 0
true / false –> 1 / 0
string –> 0…The string is read “as is”, whitespaces (includes spaces, tabs \t, newlines \n etc.) from both sides are ignored. An empty string becomes 0.
error –> NaN.

64
Q

Event type ouput sequence when a user presses a key?

A

keydown
keypress
keyup

65
Q

Event type output sequence when a user clicks the mouse?

A

mousedown
mouseup
click

65
Q

Event type output sequence when a user clicks the mouse?

A

mousedown
mouseup
click

65
Q

Event type output sequence when a user clicks the mouse?

A

mousedown
mouseup
click

66
Q

event handler syntax?

A

element.addEventListener(event,handler,[options]);

67
Q

3 ways to assign event handlers

A

HTML attribute: onclick=”…”.
DOM property: elem.onclick = function.
Methods: elem.addEventListener(event, handler[, phase]) to add, removeEventListener to remove.

68
Q

are ** and math.pow() the same?

A

yes, ** raises the first operand to the power of the second operand

ex:
8 ** 2 = 64
2 **1 = 2

69
Q

how do you create a BigInt data type?

A

appending n to the end of an integer or by calling the BigInt() function

70
Q

result??

console.log( typeof 123n );
console.log( typeof 0b10 );
console.log( typeof 123e-1 );
console.log ( typeof +”123” );
console.log( typeof 123f );

A

console.log( typeof 123n ); // “bigint” (appended n at end makes it a BigInt)

console.log( typeof 0b10 ); // “number” (b is for base, so 0 base 10 is how its read)

console.log( typeof 123e-1 ); // “number” (e is for expontent))

console.log ( typeof +”123” ); // “number”

console.log( typeof 123f ); // SyntaxError: Invalid or unexpected token

71
Q

which of the console API allows logging and sorting the data?

A

console.table(data);

72
Q

how would you remove a package from your node_modules directory?

A

npm uninstall <package_name></package_name>

73
Q

what happens to the sort() function if you do not pass in a function that specifies a sorting method

A

sorts values as “strings”

ex: let arr = [ 100, 1, 2, 15, 3 ];

gets sorted to –> [1,100,15,2,3]

74
Q

if you define a function with the new keyword, than what lexical environment can that function access?

A

Global scope

so if you define a function within a function with the new keyword, it won’t be able to access variables local to the function it was created in, like seen below, new function can’t access “value” of outer function, so throws a Reference error

function getFunc(value = “test”) {
let func = new Function(‘console.log(value)’);
return func;
}

getFunc(“hello”)();

75
Q

correct way of writing IIFE (Immediately Invoked Function Expression)?

A

(function () {
// write your js code here
})();

And here’s the arrow function style:
(() => {
// write your js code here
})() ;

76
Q

What is a IIFE?

A

Immediately Invoked Function Expression

–> JavaScript function that runs as soon as it is defined, also known as a “Self Executing Anonymous Function”

77
Q

valid ways to getting the current timestamp?

A

new Date().getTime()

Date.now()

78
Q

2 ways to filter an array by a query string?

A

arr.filter( el => el.toLowerCase().includes(query) )

arr.filter( el => el.toLowerCase().indexOf(query.toLowerCase()) !== -1 )

79
Q

what does Object.preventExtensions() do?

A

static method prevents new extensible properties from ever being added to an object

80
Q

list of some common built-in modules of NodeJS

(*just review this card answer)

A

assert - provides a set of assertion functions for verifying invariants
buffer - represent a fixed-length sequence of bytes
child_process - provides the ability to spawn child processes
cluster - splits a single Node process into multiple processes
crypto - provides cryptographic functionality
dns - enables name resolution and DNS lookups
events - handles events
fs - provides an API for interacting with the file system
http - provides an implementation of the HTTP protocol
http2 - provides an implementation of the HTTP/2 protocol
https - provides an implementation of the HTTPS protocol
net - provides an asynchronous network API for creating stream-based TCP or IPC servers
os - provides operating system-related utility methods and properties
path - provides utilities for working with file and directory paths
querystring - provides utilities for parsing and formatting URL query strings
readline - provides an interface for reading data from a Readable stream one line at a time
stream - provides an API for implementing the stream interface
string_decoder - provides an API for decoding Buffer objects into strings
timers - exposes a global API for scheduling functions to be called at some future period of time
tls - provides an implementation of the Transport Layer Security (TLS) and Secure Socket Layer (SSL) protocols that is built on top of OpenSSL
tty - provides classes used by a text terminal
url - provides utilities for URL resolution and parsing
util - supports the needs of Node.js internal APIs
v8 - exposes APIs that are specific to the version of V8 built into the Node.js binary
vm - enables compiling and running code within V8 Virtual Machine contexts
zlib - provides compression functionality

81
Q

describe:
–> call()
–> apply()
–> bind()

A

call() –> method calls a function with a given this value and arguments provided individually

apply() –> method calls a function with a given this value, and arguments provided as an array or an array-like object

bind() –> method calls a function with a given this value, and a given sequence of arguments individually

82
Q

When we install a specific package, we usually run the command line npm install package. However, we might also see the command line with an optional parameter –save or –save-dev

describe what –save and –save-dev are:

A

–save installs and adds the entry to the package.json file dependencies

–save-dev installs and adds the entry to the package.json file devDependencies

83
Q

what is JSON.stringify(value[,replacer[, space]]) ?

A

method returns a JSON string corresponding to the specified value, optionally including only certain properties or replacing property values in a user-defined manner

–>all instances of undefined are replaced with null

84
Q

what happens to “Reject” in Promises?

A

caught by closest .Catch() block, like an error would be

84
Q

what happens to “Reject” in Promises?

A

caught by closest .Catch() block, like an error would be

85
Q

which client-side storage options can store data that is persistent across page reloads or even after the browser is closed? (name 3)

A

-Local Storage
-Cookies
-IndexDB

86
Q

what does event.stopPropagation() do?
what does event.stopImmediatePropagation do?

what does event.preventDefault() do?

A

event.stopPropagation() –> method prevents any parent handlers from being executed. It prevents further propagation of the current event in the capturing and bubbling phases

event.stopImmediatePropagation –> method prevents any parent handlers as well as other handlers from being executed

event.preventDefault –>

87
Q

code snippet for setting up MySQL connection in NodeJS

*note: just look at this one

A

var mysql = require(‘mysql’);

var con = mysql.createConnection({
host: “localhost”,
user: “yourusername”,
password: “yourpassword”
});

con.connect(function(err) {
if (err) throw err;
console.log(“Connected!”);
});

88
Q

how to turn JSON data into stuff you can read in the console log and what not

A

JSON.Stringify();

*obviously value is inside the stringify() function parenthesis

89
Q

what does JSON.parse() do?

A

static method parses a JSON string

90
Q

valid events in the WebSocket API

A

-open
-close
-error
-message

91
Q

Which Schedule APIs are supported by the Timer module in Node.js??

A

-setImmediate
-setInterval
-setTimeout

92
Q

what is a RangeError ?

A

thrown when trying to pass a value as an arguement to a function that does not allow a range that includes the value

93
Q

which is the first arguement typically passed to a callback handler in Node.js?

A

Error (object)

–> null if there is no error

94
Q

push() method for arrays

A

method adds the specified elements to the end of an array and returns the new length of the array

95
Q

What is target element?
and how can you access it?

A

the most deeply nested element that caused the event

accessible as –> event.target

96
Q

What is event.currentTarget (=this)

A

the current element that handles the event (the one that has the handler on it)

–> so event.target is the most deeply nested element, but event.currentTarget keeps track of the current element as the event make its way through the capturing, target, and bubbling phase on the elements

97
Q

.length() gives the length of what data type

A

strings

–> using .length() on a number value would return undefined

98
Q

if you are sorting an array….where are the undefined elements sorted to?

A

end of the array

99
Q

what is Promise.race() ?

A

static method that takes an iterable (ie array) of promises as input and returns a single promise. This returned promise settles with the eventual state of the first promise that settles

100
Q

Window methods

*just read this one

A

Window.alert() - display an alert dialog
Window.close() - close the current window
Window.confirm() - display a dialog with a message that the user needs to respond to
Window.find() - search for a given string in a window
Window.focus() - set focus on the current window
Window.blur() - set focus away from the window
Window.open() - open a new window
Window.print() - open the Print Dialog to print the current document
Window.prompt() - return the text entered by the user in a prompt dialog
Window.resizeTo() - dynamically resize window
Window.scrollTo() - scroll to a particular set of coordinates in the document
Window.stop() - stop window loading

101
Q

some callback characteristics?

A

-callback will never be called before the completion of the current run of the JavaScript event loop

102
Q

function types related to async?
*think .then() .catch() .finally() for promises

A

try{}
catch{}
finally{}

103
Q

name some of the functions that exist in the Promise API?

A

Promise.all()
Promise.allSettled()
Promise.race()
Promise.any()

104
Q

fetch() API characteristics:

A

-returns a Promise that resolves to a Response object
-supports different request methods such as GET,POST,etc
-can take two arguements (1—> path to the resource 2–> optional which allows you to specify an object containing any custom settings you want to apply to the request…such as request method, headers, etc)

105
Q

*what happens if the values used for a && operand are not booleans?

A

if operator is used with non-boolean values –> return the last non-boolean value

ex:
let a=5;
let b=20;
let c = (b && a); –> here c=5

106
Q

how does nullish coalescing operator ?? work?

A

returns right hand side when –> left hand side operator is null or undefined

otherwise returns the left hand side

107
Q

what is the result of num and why:

var num = 5n / 2n ;

A

2n

why–> BigInt results are truncated automatically, that’s why result is 2n instead of 2.5n

*also, fyi BigInt’s cant be mixed in operations with other types –> will produce a TypeError if you try

108
Q

when using the super() keyword, what must you do??

A

use it at the beginning of the method, before accessing this or returning from the derived parent super constructor

*otherwise you will get a ReferenceError

109
Q

when adding a variable that is undefined, the result of the addition will be =

A

NaN

110
Q

how/functions to use to start a timer + check time elapsed since timer started

A

start timer –> console.time()
check timer –> console.timeEnd()

*time is outputted in miliseconds fyi

111
Q

Error Types :

*just read this, top 5 most important

A

EvalError - Creates an instance representing an error that occurs regarding the global function eval().

RangeError - Creates an instance representing an error that occurs when a numeric variable or parameter is outside its valid range.

ReferenceError - Creates an instance representing an error that occurs when de-referencing an invalid reference.

SyntaxError - Creates an instance representing a syntax error.

TypeError - Creates an instance representing an error that occurs when a variable or parameter is not of a valid type.

URIError - Creates an instance representing an error that occurs when encodeURI() or decodeURI() are passed invalid parameters.

AggregateError - Creates an instance representing several errors wrapped in a single error when multiple errors need to be reported by an operation, for example by Promise.any().

InternalError Non-standard - Creates an instance representing an error that occurs when an internal error in the JavaScript engine is thrown. E.g. “too much recursion”.

112
Q

if you initialize an array with the Array() keyword, and only put in one number without quotes like Array(2) what happens?

A

it creates an empty Array of length=2

if you want an array with a single value of 2, use quotes like this

const arr = new Array(‘2’)

113
Q

is JavaScript case-sensitive?

A

yes

114
Q

define these Array functions (only some of them)

findIndex()
find()
indexOf()

A

findIndex() –> returns the index of the first element in the array that satisfies the provided testing function
find() –> returns the value of the first element in the provided array that satisfies the provided testing function
indexOf() –> method returns the first index at which a given element can be found in the array

ex:
arr.findIndex( num => num > 13)

115
Q

how many constructors can a class have in JavaScript?

A

only 1

*there is no constructor overloading in JavaScript –> only can have 1 constructor…….–> otherwise throws SyntaxError

116
Q

correct way to get to get an extension of a file?

A

path.extname(‘main.js’)

117
Q

object.seal()

A

method seals an object
–>new properties cannot be added
–>existing properties cannot be deleted
–> prototype cannot be reassigned
–> existing writable fields can be changed in value

118
Q

Array Static methods

A

Array.from() - Creates a new Array instance from an iterable or array-like object.

Array.isArray() - Returns true if the argument is an array, or false otherwise.

Array.of() - Creates a new Array instance with a variable number of arguments, regardless of number or type of the arguments.

119
Q

what does getDay() method return?

A

day of the week:

Sunday = 0
Saturday = 6

120
Q

variable naming rules in JavaScript?

A

-first character must not be a digit
-must contain only letters, digits, or the symbols $ or _

121
Q

var variable declaration in relation to hoisting

A

variables declared using var are created before any code is executed in a process known as hoisting

–> their initial value = undefined

122
Q

Comparison between Map and Object

A

Object:
- Keys must be either a String or a Symbol.
- Keys are unordered.
- Size must be determined manually (use length is incorrect).
- Not optimized for frequent key-value pairs’ additions and removals.

Map:
- Keys can be any value (including function, objects, or primitives).
- Keys are ordered.
- Size can be determined from size property.
- Optimized for frequent key-value pairs’ additions and removals.

123
Q

can date values for date objects be overflown?

A

yes, overflown is basically what it sounds like (putting larger numbers in)

ex:
let date = new Date(2020,20,34);
console.log(date.toString());

outputs: “Mon Sep 04 2021”

*Date(year, monthIndex [, day [, hours [, minutes [, seconds [, milliseconds]]]]])

124
Q

what does the () spread syntax do?

A

allows expanding an iterable object (like an array) into the list of arguements when a list of arguements is expected

ex:
let arr = [8, 9, 15];
let merged = [0, …arr]

console.log(merged)

output–> [0, 8, 9, 15]

arr spreads the array [8, 9, 15] into a list of arguments 8, 9, 15

125
Q

what does !! do?

A

converts a non-boolean type into boolean type

*truthy / falsey value

126
Q

what does
(1 && 2 && 3) return?

A

3

*last operand that is not evaluated as falsy

127
Q

The result of a ?? b is:

*explain in basic terms how it works (Nullish coalescing operator)

A

if a is defined –then–> a

if a isn’t defined –then–> b

128
Q

how can we define a private class field in JavaScript?

A

use a hash # symbol prefix

129
Q

What is the only mathematical operator that can be used with strings?

A

+ operator (has a binary and unary form)

*everything else like - and others cannot be used with string

ex:
console.log( typeof (1 + “” + 0)) –> = string “10”

console.log(typeof (1 + “” - 0 )) —> = number 1

130
Q

the two “special quirks” of the typeof operator?

A
  1. typeof null –> = “object”
    –> result of typeof null is “object”. That’s an officially recognized error in typeof, coming from very early days of JavaScript and kept for compatibility. Definitely, null is not an object. It is a special value with a separate type of its own. The behavior of typeof is wrong here.
  2. typeof alert –> = “function”
    –> result of typeof alert is “function”, because alert is a function. We’ll study functions in the next chapters where we’ll also see that there’s no special “function” type in JavaScript. Functions belong to the object type. But typeof treats them differently, returning “function”. That also comes from the early days of JavaScript. Technically, such behavior isn’t correct, but can be convenient in practice.
131
Q

What can you do with the “os” module in NodeJS?

A

-find out the “load average”
-return the host name
-return information on the CPUs available on your system

132
Q

How do Equality Checks and Comparisons treat Null values

A

The equality check == and comparisons > < >= <= work differently.
Comparisons convert null to a number, treating it as 0. Hence, null >= 0 returns true
On the other hand, the equality check null == 0 does not get converted to a number, hence null == 0 is false.

133
Q

Difference between Attributes and Properties?

A

Attributes – is what’s written in HTML.
Properties – is what’s in DOM objects.

134
Q

What are the benefits of event delegation in JavaScript?

A

-lesser code is needed to add or remove the handlers
-event delegation simplifies the initialization as we don’t need to add multiple handlers to targeted elements
-Mass adding or removing the handlers on elements can be done easily

135
Q

the BOM (Browser Object Model) consists of :

A
  • window
  • history
  • navigator
  • screen
  • location
136
Q

the DOM (Document Object Model) consists of:

A
  • document
  • element
137
Q

correct way of initializing a XMLHttpRequest (*just read this one)

A

let xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
// Typical action to be performed when the document is ready
}
};
xhttp.open(“GET”, “https://google.com/search”, true);
xhttp.send();

138
Q

instance methods for Date object

A