Sample Questions Flashcards

1
Q

What are the standard objects available?

A

window & document

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

What is a primitive value?

A

A primitive value is a value that has no properties or methods

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

Which types (5) of primitive values are there?

A
String
Number
Boolean
Null
Undefined
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Are primitive values mutable?

A

No, Primitive values are immutable (they are hardcoded and therefore cannot be changed).

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

Can JavaScript variables contain many values?

A

Yes. Objects are variables too. But objects can contain many values.
Object values are written as name : value pairs (name and value separated by a colon).

let person = { 
firstName: "Ron" , 
lastName: "de Vries", 
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are named values, in JavaScript objects, called?

A

Properties

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

How do you call an action that can be performed on objects?

A

Methods

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

What is an object literal?

A

You define and create an object in one statement

const person = { 
firstName: "Ron", 
lastName: "de Vries",
age: 35
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How to add a new object?

A

Use the keyword new

const person2 = new Object();

person2. firstName = “Ron”,
person2. lastName = “de Vries”;

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

How are objects addressed?

A

By reference, not by value

const x = person; // Will not create a copy of person. X is not a copy of person, it is person

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

What are some flavors of JavaScript?

A

TypeScript
CoffeeScript
JScript (Microsoft)

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

What is isomorphic JavaScript?

A

Code that can be run either on the client or server side

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

Which primitive data type has been added in ES6?

A

symbol

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

Why is it dangerous to use document.write?

A

If it’s used after the page has rendered (loaded) it will delete all content

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

What is returned if user cancels the prompt() ?

A

Null

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

What does the confirm() method return?

A

A boolean value; ok = true, cancel = false

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

What is block scope?

A

Variables declared inside a code block can’t be accessed outside of that block

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

What are the logical operators?

A

&& (AND), || (OR), ! (NOT)

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

What is the result if you add a number and a string?

A

String

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

What is the difference between a function declaration and an function expression?

A

Function declarations load before any code is executed. Expressions load only when the interpreter reaches that line of code

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

How does the Ternary Operator look like? Also called Conditional operator

A

x = myBoolean ? “Ok” : “Not ok”;
It takes three expression. If statement is true (x = myBoolean) “Ok” will be executed. If fasel, “Not ok” will be printed

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

What does the NOT (!) operator return

A

True for false statements

False for true statements

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

When comparing two string, what will be greater…. 2 or 12?

A

2 will be greater, because (alphabetically), 1 is less then 2. JS always looks at the first number

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

How to secure a proper result when comparing variables?

A

Convert them into the proper type before comparison

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

How to hide an HTLM element using JavaScript?

A

Set the display style to none

document.getElementById(“demo”).style.display = “none”;

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

What is the difference between a programming language and a scripting language?

A

Programming languages are compiled, whereas scripting languages are interpreted.

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

What is JQuery?

A

jQuery was designed to focus on client-side scripting. It is an open-source JavaScript library released under the MIT license. It simplifies the syntax of DOM manipulation and eliminates cross-browser incompatibilities

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

What was server-side JavaScript (SSJS) originally called?

A

Livewire

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

What was the original name for JavaScript

A

Mocha, then Livewire, then JavaScript

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

What is VB Script?

A

VBScript is based on the full programming language, Visual Basic. It was developed by Microsoft. Unlike VBScript, JScript and ECMAScript are flavors of JavaScript.

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

What describes an object-oriented program?

A

A collection of individual objects that perform different functions.

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

Which three pop-up boxes are there?

A

alert, confirm, prompt

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

Where does JIT stand for?

A

Just In Time

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

Some programming languages? (Compiled)

A

C++
Java
Python

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

What is an object?

A

Collection of properties and methods

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

Define a car object with a drive method

A
const car = { 
    type: "Fiat", 
    model: "500", 
    color: "white",
    drive: function () { 
        return "drive"
    } };
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
37
Q

Promp returns…

A

User closes window –> NULL
User enters string + OK –> STRING
No value entered but OK click –> EMPY STRING

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

All arithmic operator become assignment operators when….

A

The arithmic operator is placed in front of the assignment operator
Example:

+=

+ is arithmic
= is assignment

+= will resolve in an assignment operator

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

What applies ‘’ the internal state of a program’’ ?

A

variables

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

When a function produces a value it is said to …..

A

return it

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

While / Do loop difference?

A

Do loop will execute it’s body at least once and only then start testing whether it should continue

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

Syntax of a For Loop?

A

for ( let i = 0, i < string.length; i ++ ) { }

1st parameter = initiate the loop
2nd parameter = expression check if loop should run
3rd parameter = counter (mostly ++ indicating to add 1 each iterarion)

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

Is JavaScript case-sensitive?

A

Yes

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

Selft contained set of related values and functions

A

Object

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

Example of a type attribute?

A

type = “application/javascript’’

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

What should a variable name start with?

A

Upper or lower case LETTER
$
Underscore

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

Give an example of assigning a variable

A

firstName = “Ron”;

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

What to use to fint out the data type?

A

typeof

Example:
console.log(typeof variablename);

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

What is A += B shorthand for? += also known as the Compound Assignment Operator

A

A = A + B;

50
Q

A snipped of code that evaluates to a value?

A

Expression

51
Q

What is type coercion?

A

Two different date types are concatenated. Solution: change date types appropriately (CASTING)

52
Q

Type Conversion

A
Converting Strings to Numbers
Converting Numbers to Strings
Converting Dates to Numbers
Converting Numbers to Dates
Converting Booleans to Numbers
Converting Numbers to Booleans
53
Q

Some Number() methods

A

Number() Returns a number, converted from its argument
parseFloat() Parses a string and returns a floating point number
parseInt() Parses a string and returns an integer

54
Q

Some Date methods

A

getDate() Get the day as a number (1-31)
getDay() Get the weekday a number (0-6)
getFullYear() Get the four digit year (yyyy)
getHours() Get the hour (0-23)
getMilliseconds() Get the milliseconds (0-999)
getMinutes() Get the minutes (0-59)
getMonth() Get the month (0-11)
getSeconds() Get the seconds (0-59)
getTime() Get the time (milliseconds since January 1, 1970)

55
Q

Converting Booleans to Numbers

A

Number(false) // returns 0

Number(true) // returns 1

56
Q

What’s the difference between putting the ++ operator before OR after the variable?

A

Main difference is the value that is returned. Points++ will return the original value THEN increase it by 1. ++points will increase FIRST and then return the new value.

Example: 
let points = 2;
points ++ // Will return 2, then increase points to 3
\++points // Will increase to 3 and then return
57
Q

What happends if number is too big or too small?

A

5e-324 will be return OR inifinity

58
Q

How to check if a value is a number?

A

Use the Number.isFinite() method.
True = value is a number

Example:
Number.isFinite(42)
—> true

59
Q

“2”+ 8 will return….

A

28
Type Coercion
JS will convert the number to a string by default

60
Q

Difference Undefine and NULL

A

Undefined is the value given to variables that have not been assigned a value. NULL means ‘no value’. It can be thought of as a placeholder. Both are non-value types.

Example:

10 + null // null behaves like zero
–> 10

10 + undefined // undefined is not a number
–> NaN

In general, values tend to be set to undefined by JS, whereas values are usually set to NULL manually by the coder

61
Q

Where does the this keyword point to in a function definition?

A

It refers to the ‘owner’ of the function

62
Q

What is the call(() method?

A

With call(), an object can use a method belonging to another object.

Example
const person = {
  fullName: function() {
    return this.firstName + " " + this.lastName;
  }
}
const person1 = {
  firstName:"John",
  lastName: "Doe"
}
const person2 = {
  firstName:"Mary",
  lastName: "Doe"
}
// This will return "John Doe":
person.fullName.call(person1);
63
Q

What is the apply() method?

A
With the apply() method, you can write a method that can be used on different objects.
The apply() method is similar to the call() method
64
Q

Examples of HTML events

A

An HTML web page has finished loading
An HTML input field was changed
An HTML button was clicked

65
Q

Example of HTML event + handler

A

The time is?

66
Q

Common HTML events

A

onchange An HTML element has been changed
onclick The user clicks an HTML element
onmouseover The user moves the mouse over an HTML element
onmouseout The user moves the mouse away from an HTML element
onkeydown The user pushes a keyboard key
onload The browser has finished loading the page

67
Q

The onload and onunload Events

A

The onload and onunload events are triggered when the user enters or leaves the page.The onload event can be used to check the visitor’s browser type and browser version, and load the proper version of the web page based on the information.

The onload and onunload events can be used to deal with cookies.

68
Q

Recommended method of Event Listeners

A

document.getElementById(“myBtn”).addEventListener(“click”, displayDate);

69
Q

addEventListener()

A

The addEventListener() method attaches an event handler to the specified element.

The addEventListener() method attaches an event handler to an element without overwriting existing event handlers.

You can add many event handlers to one element.

70
Q

Syntax of addEventListener

A

element.addEventListener(event, function, useCapture);

71
Q

What is Event bubbling? And what is Event capturing?

A

In bubbling the inner most element’s event is handled first and then the outer
In capturing the outer most element’s event is handled first and then the inner

DEFAULT = Bubbling

72
Q

removeEventListener()

A

element.removeEventListener(“mousemove”, myFunction);

73
Q

Difference between call() and apply()

A

Bij de call() method voert u de argumenten afzonderlijk in, bij de apply() method als array:

person. fullName.call(person1, “Oslo”, “Norway”);
person. fullName.apply(person1, [“Oslo”, “Norway”]);

74
Q

What is the global object?

A

n de context van client-side JavaScript is het window object het global object. Vanaf ES2020 kan naar dit object verwezen worden met globalThis.

75
Q

JS global properties

A

Infinity A numeric value that represents positive/negative infinity
NaN “Not-a-Number” value
undefined Indicates that a variable has not been assigned a value

76
Q

Global Functions

A

decodeURI() Decodes a URI
decodeURIComponent() Decodes a URI component
encodeURI() Encodes a URI
encodeURIComponent() Encodes a URI component
escape() Deprecated in version 1.5. Use encodeURI() or encodeURIComponent() instead
eval() Evaluates a string and executes it as if it was script code
isFinite() Determines whether a value is a finite, legal number
isNaN() Determines whether a value is an illegal number
Number() Converts an object’s value to a number
parseFloat() Parses a string and returns a floating point number
parseInt() Parses a string and returns an integer
String() Converts an object’s value to a string
unescape() Deprecated in version 1.5. Use decodeURI() or decodeURIComponent() instead

77
Q

Changing variables from one data type to another?

A

Casting

78
Q

What is an argument in JavaScript?

A

A value passed into a function from outside the function.

79
Q

Consider the following JavaScript function:

function myFunction(x) {
  //Insert Code Here
  }

Which code statement should be added to the function to return to the value of x multiplied by 2 to the calling statement?

A

return x * 2

80
Q

Consider the following HTML code:

Form

<div>Div
<p><br></br>Paragraph</p></div>

A

The onlick event is first captured by the element. Event capturing starts at the highest level in the DOM hierarchy tree (generally, the Window object).

81
Q

Consider the following code block:

function sample (fname, lname) {
      return fname + lname;
  }
  document.write(sample(prompt("Please enter your first name:"), prompt("Please enter your last name:")));

Output?

A

SamSmith

82
Q

Which function is created at runtime and declared without a name?

A

Anynymous functions

83
Q

What will be the output of the following code snippet?

var x = 10, y = "10.1x", z = "15xy";
var a = x + parseInt(y) + parseFloat(z);
document.write(a);
A
The parseInt(y) method returns 10, and the parseFloat(z) method returns 15. 
Output will be 35
84
Q

Which JavaScript property is used to add new properties and methods to objects?

A

Prototype

85
Q

When does the load event occur?

A

When a page finishes loading

86
Q

How does a global variable differ from a local variable?

A

You can access a global variable value from any function or block that you define on the HTML page.

87
Q

9 + true = ……

A

10

AWhen number is added to Boolean, the boolean is cast into a number first. True as 1 and false as 0

88
Q

Are Anynomous functions hoisted in JS?

A

No

89
Q

Let and const (hoisting)

A

Variables defined with let and const are hoisted to the top of the block, but not initialized.

90
Q

Which form element would you use to create a scriptable button other than a reset or submit button?

A

button

91
Q

The __________ method tests for the presence and position of a certain character.

A

indexOf()

92
Q

ServerSide JavaScript will not function if LiveWire is not installed.

A

True

93
Q

A __________ is an organized block of code that handles actions generated by user events.

A

statement

94
Q

Assuming Z= 3 and y= 2, what would be the result of : Z+=Y

A

5

95
Q

The name=value pair is the only information required to generate a cookie. All other parameters are optional.

A

True

96
Q

The select object has three event handlers: __________, __________ and __________.

A

onBlur, onFocus, onChange

97
Q

………… are used in expressions to store or return a value…..

A

Operators

98
Q

An Instance is the term for the real-time objects that are generated from the empty constructor template?

A

True

99
Q

To call the alert() method, you need only place a simple line of code, called a ___________, in a script block somewhere in your document.

A

statement

100
Q

A ______________ is used to send form contents to a server.

A

submit button

101
Q

The button object is the simplest of all objects. Its main event handler is….

A

onClick

102
Q

In JavaScript, there are __________ types of expressions.

A

4

103
Q

The main event handler associated with the radio button object is _________.

A

onClick

104
Q

__________ are the actual data values you provide in JavaScript.

A

Literals

105
Q

What would be the correct JavaScript way to make a text string appear in bold print?

A

“Hello!”.bold();

106
Q

After calling the constructor function, the keyword “constructor” returns the specific properties for the custom object to the calling instantiation statement.

A

False

107
Q

The term __________________ refers to any application, such as a Web Browser or help engine, that renders HTML for display to users.

A

user agent

108
Q

With JavaScript, it is possible to change two frames simultaneously. To do this, you must write a function that includes _________________

A

two location.href statements

109
Q

Variables can store _______ data types in JavaScript.

A

5

110
Q

A _________ creates an empty template from which real-time objects, called __________, can be generated.

A

constructor, instances

111
Q

The String, Array, Date and Math objects are all ____________ objects.

A

language

112
Q

alinkColor, anchors, bgColor, cookie and fgColor are all properties of the _______________ object.

A

document

113
Q

Examples of errors

A

Syntax error: alert(“Hi); // missing “
Runtime error: let myNumber = 42;, mynumber ++; // myNumber not defined
Logical error: concatenation instead of addition

114
Q

What is a typical watchpoint?

A

alert()

115
Q

What type of error is difficult to debug?

A

Logical error

116
Q

Consider the following code block:

var a = "10", b = 20;
                document.write( a + b );
A

1020

117
Q

Which type of error are you most likely to debug using watchpoints?

A

Logical error

118
Q

Which type of error occurs after the script has loaded and is running?

A

Run-time error

119
Q

Which type of error causes no error alert in the browser?

A

Logical

120
Q

Identify the type of error in the following code block (if any):

document.write(“Heard of the Higgs Boson?”;

A

Syntax (load-time) error because the code block has a missing closing parenthesis

121
Q

Which type of error is typically caused by improper use of commands and usually causes an error alert?

A

Run-time errors

122
Q

Identify the type of error in the following code snippet (if any):

document.writenl(“JavaScript code has hidden errors!”);

A

The statement contains a run-time error. The statement is syntactically correct, but it is trying to call the writenl method that does not exist. The correct statement which will run successfully is:

document.write(“JavaScript code has hidden errors!”);