🌍 All Study Guides📊 Dashboard📰 Blog💡 About
IBM Applied AI to IBM AI Developer Professional Certificate • STUDY MODE

PRACTICE QUIZ

QUESTION 1 OF 14

Which of the following statement is the correct way to define a function with no parameters in JavaScript?

A
function = myFunction() { }
B
function myFunction() { }Correct Answer
C
function myFunction { }
D
function = new function(myfunction)
Explanation:

This is the proper syntax to define functions in JavaScript. All parameters must be listed inside the parentheses (), and the code must be written within the curly brackets {}

QUESTION 2 OF 14

Which of the following statements is the correct way to include a script in an HTML?

A
<script name = “/source/script.js”> </script>
B
<include script = “/source/script.js”> </script>
C
<script src = “/source/script.js”> </script>Correct Answer
D
<script ref= “/source/script.js”> </script>
Explanation:

This is the correct way as it enables one to include a script directly inside the HTML document.

QUESTION 3 OF 14

How would you display a confirmation dialog box in a window?

A
window.alert(confirmation, “message”)
B
window.confirm(“message”)Correct Answer
C
window.alert(“message”)
D
window.prompt(“message”)
Explanation:

The window.confirm() method takes one argument (the message to be displayed) and creates a confirmation dialog box with OK/Cancel buttons

QUESTION 4 OF 14

Select all the following statements about errors which are true.

A
To create a new custom “InputError”, the correct code would be: throw new Error(“InputError”, “The input provided is invalid”)
B
Error instance objects contain one property which contains information about the error
C
RangeError is created when a numeric value or parameter is outside a valid rangeCorrect Answer
D
JavaScript has 6 core types of errorsCorrect Answer
Explanation:

A RangeError is only created when values are outside a valid range Explanation: The 6 core types are: RangeError, TypeError, URIError, EvalError, ReferenceError, SyntaxError GRADED QUIZ 1.In the following declaration, what is the type of the variable ‘pi’? a) var pi = “3.14”; b) number c) string (CORRECT) d) float e) char Explanation: Variables in JavaScript assumes the data type from of a variable when it’s assigned, meaning in this case `pi` is the same type as “3.14”. Since “3.14” contains multiple characters in quotation marks, it is a string. Refer to the “JavaScript Language - Overview and Syntax” and “JavaScript Variables and Control Statements” videos for more information.

QUESTION 5 OF 14

How do you define an array called array1 in JavaScript?

A
var array1 = [1,2,3]Correct Answer
B
var array1 = new Array((1,2,3))
C
var array1 = new Array[1,2,3]
D
var array1 = (1,2,3)
Explanation:

Array literals are created by declaring array elements within square brackets, as shown above. Refer to the “JavaScript Language - Overview and Syntax” video for more information.

QUESTION 6 OF 14

What does the following statement do?

A
var ndate = new Date() ;
B
Returns an error
C
Assigns the current Greenwich Mean Time to ndate
D
Assigns an empty string with the properties of dates to ndate
E
Assigns the current local time to ndateCorrect Answer
Explanation:

Providing no arguments to the Date constructor returns the current local time based on your system settings. Refer to the “JavaScript Language - Overview and Syntax” video for more information.

QUESTION 7 OF 14

Which DOM function returns a node object matching a div with an id value “example_id”?

A
document.getElementById(“example_id”)Correct Answer
B
element.getNodeById(“example_id”)
C
div.getValueOf(“example_id”)
D
document.getElementById(div, “example_id”)
Explanation:

To get an object given a specified id, the document.getElementById() method should be used. This looks for a specific id, and does not differentiate between the different tags. Refer to the “JavaScript DOM Objects” video for more information.

QUESTION 8 OF 14

How are numbers converted to strings?

A
(123).string
B
string(123)
C
(123).toString()Correct Answer
D
toString(123)
Explanation:

Converting a value to a String requires calling the “toString” method on the object (in this case numbers) and providing no arguments. Refer to the “JavaScript Language - Overview and Syntax” video for more information.

QUESTION 9 OF 14

What is the value of ‘total’ after the following statement is executed? var total = 10 + 1 +” 3”;

A
This results in an error
B
“113”Correct Answer
C
14
D
“1013”
Explanation:

JavaScript will execute this statement in order. 10 and 1 are both numbers and will be added as such (10 + 1 = 11). Then, this new value (11) will be concatenated with the string “3”, resulting in “113”. Refer to the “JavaScript – Browser Console” reading for more information.

QUESTION 10 OF 14

What would the alert be, when the following code is executed? var a = new String(“Hello”); var b = “Hello”; if (a ===b){ alert(“Same”); }else{ alert(“Different”); }

A
Same
B
DifferentCorrect Answer
C
It would not give any alert as it is an error
D
None of the above
Explanation:

The “===” operation checks if the operand on the left is of equal value and equal type to the operand on right. Since Strings declared by the String wrapper object are different than the primitive string data type, `a` and `b` are different types, despite them being the same values. Refer to the “JavaScript Language - Overview and Syntax” video and the “JavaScript – Browser Console” reading for more information.

QUESTION 11 OF 14

Which of the following is the proper way to create a `for` loop?

A
for (i < maxVal) { … }
B
loop (for i = minVal; i < maxVal; i++) { … }
C
for (var i = minVal; i < maxVal; i++) { … }Correct Answer
D
for (var i = minVal; i++; i < maxVal) { … }
Explanation:

A for loop requires 3 expressions within the parentheses: an initial expression, a conditional expression, and an increment expression. The expressions must appear in the order listed, and must be separated by a semi-colon (;), as shown in this example. Refer to the “JavaScript Variables and Control Statements” video for more information.

QUESTION 12 OF 14

Select all of the following which are properways to add a `color` property to a custom `Car` object.

A
Car.color = “Red”
B
Car.prototype(Color, “Red”)
C
Car.prototype.color = “Red”Correct Answer
D
Modify the code of the Car object directly to add a `color` parameter in the constructorCorrect Answer
Explanation:

All objects have a corresponding prototype, which make it easy to add properties and methods to all current and future instances of that object. Above is the correct usage of adding a property to a prototype. Refer to the “JavaScript Functions and Prototypes” video for more information. Explanation: Modifying the object code directly is one way to add methods and properties to it. However, there are easier ways to do so. Refer to the “JavaScript Functions and Prototypes” video for more information.

QUESTION 13 OF 14

Which of the following is not an event binder in JavaScript?

A
onmouseover
B
onhoverCorrect Answer
C
onload
D
onclick
Explanation:

Onhover is not a valid event in JavaScript. A different event binder is used for when a user hovers over an element. Refer to the “Client-Side Javascript with HTML” video for more information.

QUESTION 14 OF 14

True or False: 10car is a valid variable name in JavaScript.

A
True
B
FalseCorrect Answer

Ready to test your recall?

Which of the following statement is the correct way to define a function with no parameters in JavaScript?

A
function = myFunction() { }
B
function myFunction() { }
C
function myFunction { }
D
function = new function(myfunction)

How confident are you in this answer?