JavaScript Flashcards
How do you deserialize a JSON string into a data structure using Java
Script?
To Deserialize a JSON into a JavaScript object, here we will use a common method JSON.parse() method.
How do you serialize a data structure into a JSON string using JavaScript?
The JSON.stringify() method converts a JavaScript object or value to a JSON string, optionally replacing values if a replacer function is specified or optionally including only the specified properties if a replacer array is specified.
What are serialization and deserialization?
Serialization is a mechanism of converting the state of an object into a byte stream. Deserialization is the reverse process where the byte stream is used to recreate the actual Java object in memory. This mechanism is used to persist the object.
What is JSON?
JavaScript Object Notation (JSON) is a standard text-based format for representing structured data based on JavaScript object syntax.
If you didn’t use a loop to conditionally show or hide the views in the page, how would your JavaScript code be written instead?
We would have to add an if statement for every tab loop well loops through everything
String being assigned to the classname property of the tabs object at tabsindex
If you were to add another tab and view to your HTML, but you didn’t use event delegation, how would your JavaScript code be written instead?
Need to do query selector for each individual tab rather than query selector all
How can you retrieve the value of an element’s attribute?
To get the value of an attribute on a specified element, you call the getAttribute() method of the element:
let value = element.getAttribute(name);
What does the element.matches() method take as an argument and what does it return?
The matches() method checks to see if the Element would be selected by the provided selectorString – in other words – checks if the element “is” the selector.
What is the affect of setting an element to display: none?
display: none; When you set the value of display to none, the affected element will disappear
If you wanted to insert new clickable DOM elements into the page using JavaScript, how could you avoid adding an event listener to every new element individually?
addEventlistener on the parent element
Clicktarget put in a common element and just listen for clicks on
How can you remove an element from the DOM?
The Element.remove() method removes the element from the tree it belongs to.
What does the element.closest() method take as its argument and what does it return?
The closest() method traverses the Element and its parents (heading toward the document root) until it finds a node that matches the provided selector string. Will return itself or the matching ancestor. If no such element exists, it returns null
What DOM element property tells you what type of element it is?
Event.target same thing as querySelector elements have a tagName property
Why is it possible to listen for events on one element that actually happen its descendent elements?
Due to event flow the event bubbles
What is the event.target?
event.target returns the DOM element that triggered an specific event, so we can retrieve any property/ attribute that has a value.
When does the ‘beforeunload’ event fire on the window object?
its resources are about to be unloaded
What data type can localStorage save in the browser?
string
How to you retrieve data from localStorage?
getItem()
How do you store data localStorage
setItem()
What is the purpose of variables?
Variables are containers for storing data (storing data values).
How do you initialize (assign a value to) a variable?
In JavaScript, the equal sign (=) is an “assignment” operator
What is the purpose of a string?
JavaScript strings are for storing and manipulating text. A JavaScript string is zero or more characters written inside quotes.
What is the purpose of a number?
Number is a primitive wrapper object used to represent and manipulate numbers like 37 or -9.25 . The Number constructor contains constants and methods for working with numbers.
What is the purpose of a boolean?
Boolean is a datatype that returns either of two values i.e. true or false. In JavaScript, Boolean is used as a function to get the value of a variable, object, conditions, expressions, etc. in terms of true or false
What does the = operator mean in JavaScript?
Assignment
What is the difference between null and undefined?
In JavaScript, undefined means a variable has been declared but has not yet been assigned a value
Why is it a good habit to include “labels” when you log values to the browser
Organization
clarity