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
How would we sort an array in descending order?
arr.sort((a,b) => b - a);
26
what are the different states for a promise?
-Pending : initial state, neither fulfilled or rejected -Fulfilled : operation completed sucessfully -Rejected : operation failed
27
3 ways to define a **Function**
-Declaration decl() *inherits current scope -Expression expr() *inherits current scope -Constructor cons() *inherits global scope
28
What is the nature of how Events happen in the DOM?
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)
29
the standard DOM Events describes 3 phases of event propagation:
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
30
What is DOM?
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)
31
What is JavaScript Prototypical Inheritance?
-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
32
**JSON** characteristics?
-data-interchange format -JSON spec is based on object literal notation
33
**Object Literal Notation** characteristics?
-programming syntax
34
What do you call errors that happen in *valid code*?
runtime errors (or) exceptions
35
What do you call errors that happen in **invalid** code (code that can't be understood by the engine because it is syntactically wrong)?
parse-time errors
36
function types related to **Promises** ? *think method handling architecture design
-then -catch -finally
37
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?
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
38
how would you import **all** methods from a module called *DatePrettyPrint*
import * from '/path/DatePrettyPrint.js'; note: think --> import *
39
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; }
new Car('large','Audi'); note: **New** is the keyword
40
characteristics involving classes in JavaScript?
-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
41
splice() syntax
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].
42
describe the event **DOMContentLoaded**
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 });
43
describe the event **load**
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 });
44
3 main **White Box testing techniques** ?
-Path coverage -Branch coverage -Statement coverage
45
**White Box testing** vs **Black Box testing** ?
**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
46
Valid Cookie options:
path=/ domain=domain.com expires= 19 Jan 2038 03:14:07 GMT (*gmt string) max-age=3600 secure samesite
47
when using functions as event handlers, which parameters can they accept?
only **events** -only events can be passed into an event handler function
47
when using functions as event handlers, which parameters can they accept?
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
48
what does the **Object.assign()** method do
-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
49
what does the **Object.entries()** method do?
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] ]
50
do **arrow functions () => {}** have access to **this** ?
no -arrow functions are not bound to the object, so they do not have access to this
51
some main things to do to convert a non-async function with promise chaining to **async** function
-replace **.then** calls with **await** -make the function async, ie put **async** keyword at beginning of function *these are the main ideas
51
some main things to do to convert a non-async function with promise chaining to **async** function
-replace **.then** calls with **await** -make the function async, ie put **async** keyword at beginning of function *these are the main ideas
52
some main things to do to convert a non-async function with promise chaining to **async** function
-replace **.then** calls with **await** -make the function async, ie put **async** keyword at beginning of function *these are the main ideas
53
What is the use of breakpoint in JavaScript?
Breakpoints allow you to pause the code execution so that you can examine the current JavaScript values
53
2 ways to set the **class** for a **DOM element**
document.getElementById("myId").className = "myClass"; document.getElementById("myId").setAttribute("class","myClass");
53
2 ways to set the **class** for a **DOM element**
document.getElementById("myId").className = "myClass"; document.getElementById("myId").setAttribute("class","myClass");
54
facts about **localStorage** and **sessionStorage**
-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
55
valid ways of *Initializing* an array?
new Array() Array() [] *remember that JavaScript is case-sensitive, so array() is not the same as Array() and will throw a ReferenceError message
56
**queue** data structure for **array** define these queue array functions: **push()** **shift()** **unshift()**
-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
**stack** data structure for **array** ​ define these stack array functions: **push()** **pop()**
-LIFO **push()** --> add an element to the end **pop()** --> takes an element from the end
58
What are valid ways of accessing the defined car's properties? const car = { color: 'blue', 'the color': 'the blue' }
car.color car['color'] let theColor = 'the color'; car['${theColor}']
59
**Jest** is a popular JavaScript testing framework, name some attributes/characteristics of it?
-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
**Jest** is a popular JavaScript testing framework, name some attributes/characteristics of it?
-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
when defining the package version, what are the rules for **semantic versioning** and its version numbers?
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
**Map** methods: also what is a Map?
**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
**Set** methods: also what is a Set?
**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
Numeric Conversions: for values like: -undefined -null -true/false -string -error
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
Event type ouput sequence when a user presses a key?
keydown keypress keyup
65
Event type output sequence when a user clicks the mouse?
mousedown mouseup click
65
Event type output sequence when a user clicks the mouse?
mousedown mouseup click
65
Event type output sequence when a user clicks the mouse?
mousedown mouseup click
66
event handler syntax?
element.addEventListener(event,handler,[options]);
67
3 ways to assign **event handlers**
**HTML attribute**: onclick="...". **DOM property**: elem.onclick = function. **Methods**: elem.addEventListener(event, handler[, phase]) to add, removeEventListener to remove.
68
are ** and math.pow() the same?
yes, ** raises the first operand to the power of the second operand ex: 8 ** 2 = 64 2 **1 = 2
69
how do you create a BigInt data type?
appending **n** to the end of an integer or by calling the BigInt() function
70
result?? console.log( typeof 123n ); console.log( typeof 0b10 ); console.log( typeof 123e-1 ); console.log ( typeof +"123" ); console.log( typeof 123f );
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
which of the console API allows logging and sorting the data?
console.table(data);
72
how would you remove a package from your node_modules directory?
npm uninstall
73
what happens to the sort() function if you do not pass in a function that specifies a sorting method
sorts values as "strings" ex: let arr = [ 100, 1, 2, 15, 3 ]; gets sorted to --> [1,100,15,2,3]
74
if you define a function with the **new** keyword, than what lexical environment can that function access?
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
correct way of writing IIFE (Immediately Invoked Function Expression)?
(function () { // write your js code here })(); And here's the arrow function style: (() => { // write your js code here })() ;
76
What is a IIFE?
Immediately Invoked Function Expression --> JavaScript function that runs as soon as it is defined, also known as a "Self Executing Anonymous Function"
77
valid ways to getting the current timestamp?
new Date().getTime() Date.now()
78
2 ways to filter an array by a query string?
arr.filter( el => el.toLowerCase().**includes**(query) ) arr.filter( el => el.toLowerCase().**indexOf**(query.toLowerCase()) !== -1 )
79
what does **Object.preventExtensions()** do?
static method prevents new extensible properties from ever being added to an object
80
list of some common built-in modules of NodeJS (*just review this card answer)
**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
describe: --> **call()** --> **apply()** --> **bind()**
**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
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:
**--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
what is **JSON.stringify(value[,replacer[, space]])** ?
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
what happens to "Reject" in Promises?
caught by closest .Catch() block, like an error would be
84
what happens to "Reject" in Promises?
caught by closest .Catch() block, like an error would be
85
which client-side storage options can store data that is persistent across page reloads or even after the browser is closed? (name 3)
-Local Storage -Cookies -IndexDB
86
what does **event.stopPropagation()** do? what does **event.stopImmediatePropagation** do? what does **event.preventDefault()** do?
**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
code snippet for setting up MySQL connection in NodeJS *note: just look at this one
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
how to turn **JSON** data into stuff you can read in the console log and what not
JSON.Stringify(); *obviously value is inside the stringify() function parenthesis
89
what does **JSON.parse()** do?
static method parses a JSON string
90
valid events in the **WebSocket API**
-open -close -error -message
91
Which Schedule APIs are supported by the Timer module in Node.js??
-setImmediate -setInterval -setTimeout
92
what is a **RangeError** ?
thrown when trying to pass a value as an arguement to a function that does not allow a range that includes the value
93
which is the first arguement typically passed to a callback handler in Node.js?
**Error** (object) --> **null** if there is no error
94
**push()** method for arrays
method adds the specified elements to the end of an array **and** returns the new length of the array
95
What is **target** element? and how can you access it?
the **most deeply nested element** that caused the event accessible as --> **event.target**
96
What is **event.currentTarget (=this)**
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
**.length()** gives the length of what **data type**
**strings** --> using .length() on a number value would return undefined
98
if you are sorting an array....where are the **undefined** elements sorted to?
end of the array
99
what is **Promise.race()** ?
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
Window methods *just read this one
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
some **callback** characteristics?
-**callback** will never be called before the completion of the current run of the JavaScript event loop
102
function types related to **async**? *think .then() .catch() .finally() for promises
try{} catch{} finally{}
103
name some of the functions that exist in the Promise API?
Promise.all() Promise.allSettled() Promise.race() Promise.any()
104
fetch() API characteristics:
-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
*what happens if the values used for a **&&** operand are not booleans?
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
how does nullish coalescing operator **??** work?
returns right hand side when --> left hand side operator is **null** or **undefined** otherwise returns the left hand side
107
what is the result of num and why: var num = 5n / 2n ;
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
when using the **super()** keyword, what must you do??
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
when adding a variable that is **undefined**, the result of the addition will be =
NaN
110
how/functions to use to **start** a timer + **check time elapsed since timer started**
start timer --> **console.time()** check timer --> **console.timeEnd()** *time is outputted in miliseconds fyi
111
Error Types : *just read this, top 5 most important
**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
if you initialize an array with the **Array()** keyword, and only put in one number without quotes like **Array(2)** what happens?
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
is JavaScript case-sensitive?
yes
114
define these **Array functions** (only some of them) findIndex() find() indexOf()
**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
how many constructors can a class have in JavaScript?
only 1 *there is no constructor overloading in JavaScript --> only can have 1 constructor.......--> otherwise throws **SyntaxError**
116
correct way to get to get an extension of a file?
**path**.extname('main.js')
117
object.**seal()**
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
Array **Static** methods
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
what does **getDay()** method return?
day of the week: Sunday = 0 Saturday = 6
120
variable naming rules in JavaScript?
-first character must not be a digit -must contain **only** letters, digits, or the symbols $ or _
121
**var** variable declaration in relation to hoisting
variables declared using **var** are created before any code is executed in a process known as hoisting --> their initial value = undefined
122
Comparison between **Map** and **Object**
**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
can date values for date objects be **overflown**?
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
what does the (**...**) **spread** syntax do?
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
what does **!!** do?
converts a non-boolean type into boolean type *truthy / falsey value
126
what does (1 && 2 && 3) return?
3 *last operand that is not evaluated as falsy
127
The result of **a ?? b** is: *explain in basic terms how it works **(Nullish coalescing operator)**
if **a** is **defined** --then--> a if **a** **isn't defined** --then--> b
128
how can we define a private class field in JavaScript?
use a hash **#** symbol prefix
129
What is the only mathematical operator that can be used with **strings**?
**+** 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
the two "special quirks" of the **typeof** operator?
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
What can you do with the "os" module in NodeJS?
-find out the "load average" -return the host name -return information on the CPUs available on your system
132
How do **Equality Checks** and **Comparisons** treat **Null** values
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
Difference between **Attributes** and **Properties**?
**Attributes** – is what’s written in **HTML**. **Properties** – is what’s in **DOM objects**.
134
What are the benefits of **event delegation** in JavaScript?
-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
the **BOM (Browser Object Model)** consists of :
- window - history - navigator - screen - location
136
the **DOM (Document Object Model)** consists of:
* document * element
137
correct way of initializing a XMLHttpRequest (*just read this one)
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
instance methods for Date object