JavaScript Flashcards

1
Q

How do you deserialize a JSON string into a data structure using Java
Script?

A

To Deserialize a JSON into a JavaScript object, here we will use a common method JSON.parse() method.

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

How do you serialize a data structure into a JSON string using JavaScript?

A

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.

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

What are serialization and deserialization?

A

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.

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

What is JSON?

A

JavaScript Object Notation (JSON) is a standard text-based format for representing structured data based on JavaScript object syntax.

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

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?

A

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

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

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?

A

Need to do query selector for each individual tab rather than query selector all

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

How can you retrieve the value of an element’s attribute?

A

To get the value of an attribute on a specified element, you call the getAttribute() method of the element:

let value = element.getAttribute(name);

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

What does the element.matches() method take as an argument and what does it return?

A

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.

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

What is the affect of setting an element to display: none?

A

display: none; When you set the value of display to none, the affected element will disappear

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

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?

A

addEventlistener on the parent element

Clicktarget put in a common element and just listen for clicks on

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

How can you remove an element from the DOM?

A

The Element.remove() method removes the element from the tree it belongs to.

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

What does the element.closest() method take as its argument and what does it return?

A

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

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

What DOM element property tells you what type of element it is?

A

Event.target same thing as querySelector elements have a tagName property

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

Why is it possible to listen for events on one element that actually happen its descendent elements?

A

Due to event flow the event bubbles

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

What is the event.target?

A

event.target returns the DOM element that triggered an specific event, so we can retrieve any property/ attribute that has a value.

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

When does the ‘beforeunload’ event fire on the window object?

A

its resources are about to be unloaded

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

What data type can localStorage save in the browser?

A

string

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

How to you retrieve data from localStorage?

A

getItem()

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

How do you store data localStorage

A

setItem()

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

What is the purpose of variables?

A

Variables are containers for storing data (storing data values).

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

How do you initialize (assign a value to) a variable?

A

In JavaScript, the equal sign (=) is an “assignment” operator

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

What is the purpose of a string?

A

JavaScript strings are for storing and manipulating text. A JavaScript string is zero or more characters written inside quotes.

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

What is the purpose of a number?

A

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.

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

What is the purpose of a boolean?

A

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

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

What does the = operator mean in JavaScript?

A

Assignment

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

What is the difference between null and undefined?

A

In JavaScript, undefined means a variable has been declared but has not yet been assigned a value

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

Why is it a good habit to include “labels” when you log values to the browser

A

Organization

clarity

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

Give five examples of JavaScript primitives.

A

undefined, null, boolean, string and number

29
Q

What data type is returned by an arithmetic operation?

A

single numerical value

30
Q

What is string concatenation?

A

The JavaScript concatenation operator is a plus sign (+). This operator lets you add the contents of two or more strings together to create one

31
Q

What purpose(s) does the + plus operator serve in JavaScript?

A

The + operator is used to perform both addition and string concatenation in JavaScript

32
Q

What data type is returned by comparing two values (, ===, etc)?

A

Comparison operators — operators that compare values and return true or false

33
Q

What does the += “plus-equals” operator do?

A

The plus-equals operator ( += ) adds the value on the right, to the variable on the left, and then assigns that value back into the variable on the left

34
Q

What are object properties?

A

property is an association between a name (or key) and a value.

35
Q

Describe object literal notation.

A

Object property value

36
Q

How do you remove a property from an object?

A

delete.property

37
Q

How do you calculate the last index of an array?

A

Object.length-1 students[students.length - 1]

38
Q

What is the length property of an array?

A

Stores a count of how many items are in an array

39
Q

How do you calculate the last index of an array?

A

Object.length-1 students[students.length - 1]

40
Q

Why do we log things to the console?

A

The console.log() method outputs a message to the web console

41
Q

What is a method?

A

A method is a function which is a property of an object. There are two kind of methods: Instance Methods which are built-in tasks performed by an object instance, or Static Methods which are tasks that are called directly on an object constructor.

42
Q

How do you remove the last element from an array?How do you round a number down to the nearest integer?How do you round a number down to the nearest integer?

A

pop() method.

43
Q

How do you generate a random number?

A

Math.random()

44
Q

How do you delete an element from an array?

A

The splice() method changes the contents of an array by removing or replacing existing elements and/or adding new elements in place

45
Q

How do you append an element to an array?

A

1) The push() method adds one or more elements to the end of an array and returns the new length of the array. …
2) The unshift() method adds one or more elements to the beginning of an array and returns the new length of the array: var a = [1, 2, 3]; a.

46
Q

How do you break a string up into an array?

A

The split() method

47
Q

Do string methods change the original string? How would you check if you
weren’t sure?

A

No they don’t

48
Q

Roughly how many string methods are there according to the MDN Web docs?

A

38ish

49
Q

Is the return value of a function or method useful in every situation?

A

No ,ex push gives return value that is not needed length may not be needed at the moment

50
Q

Roughly how many array methods are there according to the MDN Web docs?

A

50ish

51
Q

What three-letter acronym should you always include in your Google search about a JavaScript method or CSS property?

A

MDN

52
Q

Give 6 examples of comparison operators.

A

,>=,<=, ===,!==

53
Q

What data type do comparison expressions evaluate to?

A

single Boolean value of either True or False

54
Q

Is else required in order to use an if statement?

A

no

55
Q

Describe the syntax (structure) of an if statement.

A

check the expression to see whether a condition is met and returns a value based on the output obtained

56
Q

What are the three logical operators?

A

||,&&, !

57
Q

How do you compare two different expressions in the same condition?

A

Logical oeprators

58
Q

What is the purpose of a loop?

A

to repeat the same, or similar, code a number of times

59
Q

What is the purpose of a condition expression in a loop?

A

the stopping/breaks of an expression of the loop

60
Q

What does “iteration” mean in the context of loops?

A

number of times loop will be repeated

61
Q

What does “iteration” mean in the context of loops?

A

number of times loop will be repeated

62
Q

When does the condition expression of a while loop get evaluated?

A

each loop iteration

63
Q

When does the initialization expression of a for loop get evaluated?

A

as the loop begins

64
Q

When does the final expression of a for loop get evaluated?

A

each time after the code block runs

65
Q

Besides a return statement, which exits its entire function block, which keyword
exits a loop before its condition expression evaluates to false?

A

BREAK

66
Q

What does the ++ increment operator do?

A

adds and reassigns value

67
Q

How do you iterate through the keys of an object?

A

for in loop

68
Q

How do you serialize a data structure into a JSON string using JavaScript?

A

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.