Intermediate JavaScript Flashcards

1
Q

What is the DOM

A

Document Object Model

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

What is the Virtual DOM?

A

A virtual DOM is a lightweight JavaScript representation of the DOM used in declarative web frameworks such as React, Vue.js, and Elm. Updating the virtual DOM is comparatively faster than updating the actual DOM.

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

Window Object

A

Represents the browser window

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

Document Object

A

Represents the web page

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

Image Object

A

Represents an HTML IMG tag

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

History Object

A

Contains browser history

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

Navigator Object

A

Contains niformation about the visitor’s browser

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

All global JS objects, functions and variables automatically become….

A

members of the window object

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

Global variables (Window object) are…

A

properties of the window object

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

Global functions (window object) are..

A

methods of the window object

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

Some methods of the Window Object

A

window. open
window. close
window. moveTo
window. resizeTo

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

Finding HTML (Document Object), few examples

A

getElementsById
getElementsByTagName
getElementsByClassName

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

Changing HTML (Document Object)

A

element. innerHTML =
element. attribute =
element. setAttribute (attribute,value)

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

Adding or Deleting Elements (Document Object)

A

document. createElement(element)
document. removeChild(element)
document. appendChild(element)

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

Event Handler (Document Object)

A

document.getElementById(id).onclick = function () {code}

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

Create an Image Object

A

const x = document.createElement(“IMG”)

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

Some Image Object properties

A

complete
naturalHeigth
naturalWidth
src

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

Image rollover?

A

Two images. Change onMouseOver and onMouseOut

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

Return the anchor part of a URL (Location Object)

A

var x = location.hash;

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

Which Methods are there for the Location Object?

A

assign() Loads a new document
reload() Reloads the current document
replace() Replaces the current document with a new one

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

Difference between replace or assign (location object)

A

After using replace the current page will not be saved in the session history

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

Which Navigator propertie returns the version of the browser?

A

appVersion

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

Which Navigator object returns the operating system?

A

platform

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

Which Navigator property returns the name of the browser?

A

appName

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

Which three methods to extract a part of String are there?

A

slice(start, end)
substring(start, end)
substr(start, length)

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

What does slice()? (String)

A

extracts a part of a string and returns the extracted part in a new string.

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

What doest the substring() method?

A

substring() is similar to slice().

The difference is that substring() cannot accept negative indexes.

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

What does the substr() method?

A

substr() is similar to slice().

The difference is that the second parameter specifies the length of the extracted part.

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

Difference between indexOf() and search() method?

A
The search() method cannot take a second start position argument.
The indexOf() method cannot take powerful search values (regular expressions).
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
30
Q

String.match….

A

The match() method searches a string for a match against a regular expression, and returns the matches, as an Array object.

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

What is a regular expression? Regexp

A

A regular expression is a sequence of characters that forms a search pattern.
The search pattern can be used for text search and text replace operations.

32
Q

In JavaScript, regular expressions are often used with the two string methods: search() and replace().

A

The search() method uses an expression to search for a match, and returns the position of the match.

The replace() method returns a modified string where the pattern is replaced.

33
Q

Regular Expression Patterns

A

Brackets are used to find a range of characters:

Expression
[abc] Find any of the characters between the brackets
[0-9] Find any of the digits between the brackets
(x|y) Find any of the alternatives separated with |
Metacharacters are characters with a special meaning:

Metacharacter
\d Find a digit
\s Find a whitespace character
\b Find a match at the beginning of a word like this: \bWORD, or at the end of a word like this: WORD\b
\uxxxx Find the Unicode character specified by the hexadecimal number xxxx

34
Q

RegExp Object

A

In JavaScript, the RegExp object is a regular expression object with predefined properties and methods.

35
Q

Reg Exp Object methods

A

exec() Tests for a match in a string. Returns the first match
test() Tests for a match in a string. Returns true or false
toString() Returns the string value of the regular expression

36
Q

What type of error is most likely to debug using watchpoints?

A

Logical

37
Q

What is a typical watchpoint in JS?

A

alert()

38
Q

What type of error after script has loaded?

A

Run-time

39
Q

What are run time erros typically caused by?

A

Improper use of commands

40
Q

Syntax-error

A

Load time (also called compiler / interpreter error)

41
Q

What to use to repeat a group of statement fora particular range of values?

A

For loop

42
Q

Control structures…

A

Make decisions based on Boolean values

43
Q

Substitute for the neste if..else statement?

A

Switch

44
Q

Purpose of the switch statement?

A

To compare a value against another to search for a match

45
Q

Purpose of the break statement?

A

To exit a control structure

46
Q

Continue statement..

A

Force the flow of control back to the top of the loop

47
Q

How to check if Java is enabled?

A

Use javaEnabled() method (navigator object)

48
Q

Limitation of virtual DOM?

A

Changes aren’t directly reflected on the webpage

49
Q

The history object has one property….

A

length

50
Q

What is the JS equivalent fo the browser’s back button?

A

history.go(-1);

51
Q

What is the default object in JS?

A

Window

52
Q

How to bring a window object to the top?

A

window.moveTo()

53
Q

Create a new history entry?

A

pushstate()

54
Q

Diffing =

A

comparing the new virtual DOM with previous version

55
Q

window.open() method uses 3 segments

A

URL, window name and list of window

56
Q

Comma delimited list from array

A

Use myArray.join(“,”);

57
Q

Declare a regular expression:

A

var ex = /Ron/;

58
Q

Difference between shift and pop

A

shift removes and returns the first element, pop the last element

59
Q

How to extract username from var email = ron@outlook.com

A

email.substring(0, email.indexOf(“@”)
0 = starting index
@ = starting index –> up to (in this case @ )

60
Q

To use any Data or Time you must create a new instance or copy

A

var mydate = new Date();

61
Q

How to repeat a method or command after x-time

A

setTimeOut()

function.setTimeOut(time);

62
Q

The join() method, by default, uses the….

A

comma seperator

63
Q

Why use regular expression instead of string for matching?

A

regular expression can match a large number of strings

64
Q

Math.random returns…

A

any value in range 0 - 1 with 0 included and 1 excluded

65
Q

getDate() returns…

A

The date number (17 if it’s 17th of november)

66
Q

Regex, string, Math, Array, Date are….

A

language objects

67
Q

String length is…

A

string.length (NOT a method so no brackets)

68
Q

floor, ceil, sin are…

A

Math objects

69
Q

substr() method takes two parameters…

A
  1. Starting index

2. Number of characters to extract

70
Q

charAt() example..

A

firstName.charAt(4);

71
Q

What is a JS class?

A
A JavaScript class is not an object.
It is a template for JavaScript objects.
72
Q

THe prototype is available in …… JS object

A

every

73
Q

Inheritance =

A

class-based and prototype based

74
Q

Yield operator

A

Pause or resume a generator function

75
Q

Add additional fields to custom object…

A

Use prototype

76
Q

Which object can access items in a collection?

A

Iterator

77
Q

Call the functions on a paretn object?

A

Use the super keyword