PRACTICE QUIZ
Which of the following statement is the correct way to define a function with no parameters in JavaScript?
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 {}
Which of the following statements is the correct way to include a script in an HTML?
This is the correct way as it enables one to include a script directly inside the HTML document.
How would you display a confirmation dialog box in a window?
The window.confirm() method takes one argument (the message to be displayed) and creates a confirmation dialog box with OK/Cancel buttons
Select all the following statements about errors which are true.
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.
How do you define an array called array1 in JavaScript?
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.
What does the following statement do?
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.
Which DOM function returns a node object matching a div with an id value “example_id”?
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.
How are numbers converted to strings?
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.
What is the value of ‘total’ after the following statement is executed? var total = 10 + 1 +” 3”;
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.
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”); }
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.
Which of the following is the proper way to create a `for` loop?
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.
Select all of the following which are properways to add a `color` property to a custom `Car` object.
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.
Which of the following is not an event binder in JavaScript?
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.
True or False: 10car is a valid variable name in JavaScript.
Ready to test your recall?
Which of the following statement is the correct way to define a function with no parameters in JavaScript?
How confident are you in this answer?