




























































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Earlier version of CIW JavaScript exam, covering functions, objects, forms, error handling, and ECMAScript standards.
Typology: Exams
1 / 181
This page cannot be seen from the preview
Don't miss anything!





























































































Question 1. Which of the following best describes JavaScript? A) Compiled, statically-typed language B) Object-based, interpreted scripting language C) Procedural, compiled language D) Markup language Answer: B Explanation: JavaScript is an object-based scripting language that is interpreted, not compiled, and is primarily used to add interactivity to web pages. Question 2. Which of these can JavaScript run on? A) Only client-side B) Only server-side
C) Both client-side and server-side D) Only in desktop applications Answer: C Explanation: JavaScript can run on both the client side (in the browser) and the server side (using environments like Node.js). Question 3. What is the correct syntax to declare a variable in JavaScript? A) let myVar; B) variable myVar; C) int myVar; D) declare myVar; Answer: A
A) B) # comment C) // comment D) /* comment */ Answer: C Explanation: Single-line comments in JavaScript start with //. Question 6. What is the result of the expression: 2 + '2' in JavaScript? A) 4 B) 22 C) '4' D) Error
Answer: B Explanation: Adding a number and a string results in string concatenation, so the result is '22'. Question 7. What will the following code output? console.log(typeof true); A) "string" B) "number" C) "boolean" D) "object" Answer: C Explanation: The typeof operator returns "boolean" for boolean values.
B) def myFunc() {} C) func myFunc() {} D) define myFunc() {} Answer: A Explanation: Functions in JavaScript are defined using the function keyword. Question 10. What is the value of y after the following code executes? let y = 5; y += 3; A) 5 B) 8
Answer: B Explanation: y += 3 adds 3 to the value of y, resulting in 8. Question 11. Which operator is used to compare both value and type in JavaScript? A) == B) = C) === D) != Answer: C
A) if x = 5 then {} B) if (x == 5) {} C) if x == 5: D) if (x = 5) {} Answer: B Explanation: The correct syntax is if (condition) {}. Question 14. What will happen if you try to access a variable declared with let before its declaration? A) Returns undefined B) Throws a ReferenceError C) Returns null
D) Initializes with zero Answer: B Explanation: Variables declared with let are not hoisted and will cause a ReferenceError if accessed before declaration. Question 15. Which statement is used to exit a loop in JavaScript? A) exit B) break C) stop D) return Answer: B Explanation: The break statement exits a loop immediately.
A) Exits the loop B) Skips the current iteration and continues with the next C) Stops the program D) Restarts the loop Answer: B Explanation: continue skips the current iteration and moves to the next one. Question 18. How can you create an array in JavaScript? A) let arr = (1, 2, 3); B) let arr = [1, 2, 3]; C) let arr = {1, 2, 3};
D) let arr = <1, 2, 3>; Answer: B Explanation: Arrays are created using square brackets. Question 19. Which method can be used to convert a string to an integer in JavaScript? A) parseInt() B) toString() C) Number() D) Both A and C Answer: D Explanation: Both parseInt() and Number() can convert strings to numbers, though parseInt() parses up to the first non-digit character.
A) for (initialization; condition; increment) {} B) for initialization; condition; increment {} C) for (initialization, condition, increment) {} D) for {initialization; condition; increment;} Answer: A Explanation: The correct structure uses parentheses and semicolons. Question 22. Which of the following will NOT trigger a JavaScript event handler? A) onclick B) onmouseover C) onsubmit
D) onloadimg Answer: D Explanation: "onloadimg" is not a valid event; the correct event is "onload". Question 23. How do you access the first element of an array named fruits? A) fruits[1] B) fruits. C) fruits[0] D) fruits.first Answer: C Explanation: Arrays in JavaScript are zero-indexed.
B) function add(a, b): return a + b C) add(a, b) = a + b D) function add(a, b) => a + b; Answer: A Explanation: The correct JavaScript function uses curly braces and the return statement. Question 26. Which method adds a new element to the end of an array? A) unshift() B) push() C) pop() D) shift()
Answer: B Explanation: push() adds elements to the end of an array. Question 27. What will happen if you try to redeclare a variable with let in the same scope? A) It will overwrite the variable B) It will throw a SyntaxError C) It will ignore the redeclaration D) It will assign undefined Answer: B Explanation: Redeclaring a variable with let in the same scope is not allowed.