JavaScript Cert Flashcards
Two main properties of an Error object thats passed as an arguement to catch in a try..catch?
Name
Message
Advantages of using Node.js ? (name three)
Asynchronous
Open Source
Non-Blocking
Valid Events when interacting with the browser?
-mousedown
-contextmenu
-keyup
describe “Modules”
-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
correct syntax for accessing the property of an object in JavaScript?
The correct syntax for accessing the property of an object is:
- objectName.property
- objectName[“property”]
- objectName[expression]
name some “JavaScript Frameworks”
Angular
Node.js
React
“Falsy” values:
- 0
- null
- undefined
- NaN
- ”” or ‘’ (empty string)
- false
valid data types in JavaScript:
-null
-undefined
-Object
-Symbol
-Number
-String
-BigInt
-Boolean
correct way to look for an element by its ID
document.getElementById(‘element’);
What are the 2 most important items in your npm package.json file if you plan to publish a package?
-Name
-Version
*these 2 together establish a unique identifier for your published package
*optional if not going to publish
3 Phases of Event Propagation in standard DOM
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 do Events in the Target Phase trigger?
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.
What is a “Curried Function”?
“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.
If a function does not return a value, its value is equal to = __________
undefined
should you ever add a “new line” between return and the value? (Y/N)
No
jQuery libarary defines a function with ______?
Lodash library defines its main function with ______?
jQuery = “$”
Lodash = “_”
3 most popular “Testing Frameworks” used by JavaScript developers?
-Puppeteer
-Mocha
-Jasmine
Describe “Mocha” Testing Framework?
-feature rich JavaScript test framework running on Node.Js and in the browser
-makes Asynchronous testing simple and fun (synchronous testing also)
Describe “Puppeteer” Testing Framework?
Node library which provides a high-level API to control headless Chrome or Chromium over the DevTools Protocol
Describe “Jasmine” Testing Framework?
Behavior Driven development framework,
for testing JavaScript code
what is JUnit ?
unit testing framework for the** Java** (not JavaScript) programming language
describe a Callback function ?
a function passed into a function to be called later
by default, the sort() function sorts values as _____?
strings
How would we sort an array in ascending order?
arr.sort((a,b) => a - b );
How would we sort an array in descending order?
arr.sort((a,b) => b - a);
what are the different states for a promise?
-Pending : initial state, neither fulfilled or rejected
-Fulfilled : operation completed sucessfully
-Rejected : operation failed
3 ways to define a Function
-Declaration decl() *inherits current scope
-Expression expr() *inherits current scope
-Constructor cons() *inherits global scope
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)
the standard DOM Events describes 3 phases of event propagation:
- Capturing phase - the event goes down to the element
- Target phase - the event reached the target element
- Bubbling phase - the event bubbles up from the element
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)
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
JSON characteristics?
-data-interchange format
-JSON spec is based on object literal notation
Object Literal Notation characteristics?
-programming syntax
What do you call errors that happen in valid code?
runtime errors
(or) exceptions
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
function types related to Promises ?
*think method handling architecture design
-then
-catch
-finally
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
how would you import all methods from a module called DatePrettyPrint
import * from ‘/path/DatePrettyPrint.js’;
note: think –> import *
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
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
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].
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
});
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
});
3 main White Box testing techniques ?
-Path coverage
-Branch coverage
-Statement coverage
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
Valid Cookie options:
path=/
domain=domain.com
expires= 19 Jan 2038 03:14:07 GMT (*gmt string)
max-age=3600
secure
samesite
when using functions as event handlers, which parameters can they accept?
only events
-only events can be passed into an event handler function
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
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
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] ]
do arrow functions () => {} have access to this ?
no
-arrow functions are not bound to the object, so they do not have access to this
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
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
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
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
2 ways to set the class for a DOM element
document.getElementById(“myId”).className = “myClass”;
document.getElementById(“myId”).setAttribute(“class”,”myClass”);
2 ways to set the class for a DOM element
document.getElementById(“myId”).className = “myClass”;
document.getElementById(“myId”).setAttribute(“class”,”myClass”);
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