0% found this document useful (0 votes)
2K views

Introduction To Javascript Questions

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2K views

Introduction To Javascript Questions

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

JavaScript Certification Practice Questions

Please answer these as best as you can. Do not look back to your reviewers or research. After answering all
the questions, self-check by looking at the correct answers. Good luck!

ARE YOU READY NOW? LET’S START!

1. What is the purpose of the var keyword in JavaScript?

A. To create a constant
B. To declare a variable
C. To define a function
D. To create a block-scoped variable

2. Which of the following is true about let in JavaScript?

A. It declares a variable with function scope


B. It creates a global variable
C. It has block-level scope
D. It is not used for declaring variables

3. What does the const keyword do?

A. Declares a variable that can be reassigned


B. Creates a constant that cannot be reassigned
C. Declares a global variable
D. Creates a variable with block scope

4. What is the correct syntax to create an object in JavaScript?

A. let obj = {};


B. let obj = [];
C. let obj = function();
D. let obj = Object();

5. How do you add a new property to an object in JavaScript?


A. object.addProperty('key', value)
B. object['key'] = value
C. object.add('key', value)
D. object.set('key', value)

6. What does the this keyword refer to in JavaScript?

A. The current function


B. The global object
C. The object that is executing the current function
D. The last declared variable

7. Which of the following is a correct way to define a function in JavaScript?

A. function myFunction() {}
B. function = myFunction() {}
C. def myFunction() {}
D. function: myFunction() {}

8. What does the return statement do in a function?

A. Stops the function execution and returns a value


B. Creates a new function
C. Prevents the function from executing
D. Logs the value to the console

9. Which of the following is used to loop over an array in JavaScript?

A. forEach()
B. loop()
C. repeat()
D. iterate()

10. What is the result of typeof null in JavaScript?

A. "null"
B. "object"
C. "undefined"
D. "array"

11. How would 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 = array(1, 2, 3)

12. Which method would you use to convert a string to an integer in JavaScript?

A. parseInt()
B. toInteger()
C. convertToInt()
D. stringToInt()

13. What is the purpose of JSON.stringify() in JavaScript?

A. To convert an object into a JSON string


B. To parse a JSON string into an object
C. To sort an object
D. To handle errors in JSON

14. What does the push() method do in JavaScript?

A. Adds a new element to the beginning of an array


B. Adds a new element to the end of an array
C. Removes the last element of an array
D. Removes the first element of an array

15. Which operator is used for strict equality comparison in JavaScript?

A. ==
B. ===
C. =
D. !=
16. What is a closure in JavaScript?

A. A function inside an object


B. A function that can access variables from its outer scope
C. A way to close a program
D. A method that closes the console

17. What does the map() method do in JavaScript?

A. Filters out elements from an array


B. Creates a new array with the results of calling a function on every element of the array
C. Modifies an array in place
D. Sorts the elements of an array

18. Which of the following will trigger an error in JavaScript?

A. let x = 10; x = 20;


B. const y = 30; y = 40;
C. var z = 50; z = 60;
D. let a = 70; a = 80;

19. How do you handle errors in JavaScript?

A. catch block
B. try...catch statement
C. error() function
D. handleError() function

20. Which of the following methods is used to remove the last element of an array in
JavaScript?

A. pop()
B. shift()
C. unshift()
D. splice()

21. What is the correct syntax for a JavaScript class?


A. class MyClass {}
B. class = MyClass {}
C. class MyClass[]
D. function class MyClass {}

22. Which of the following methods is used to execute code asynchronously in


JavaScript?

A. setTimeout()
B. setInterval()
C. async/await
D. all()

23. What is the difference between null and undefined in JavaScript?

A. null is a type, undefined is a value


B. null is an object, undefined is a primitive value
C. null is a primitive value, undefined is an object
D. There is no difference

24. Which event is used to trigger an action when an element is clicked in JavaScript?

A. onmouseover
B. onkeydown
C. onclick
D. onload

25. What does JSON.parse() do in JavaScript?

A. Converts a JavaScript object to a JSON string


B. Converts a JSON string into a JavaScript object
C. Creates a JSON string
D. Throws an error if the input is not valid JSON
26. What will console.log(typeof NaN) output?

A. "number"
B. "NaN"
C. "undefined"
D. "object"

27. How can you prevent a form from submitting in JavaScript?

A. form.preventDefault();
B. event.preventDefault();
C. form.stopSubmit();
D. event.stopSubmit();

28. Which operator is used to concatenate strings in JavaScript?

A. +
B. &
C. concat()
D. +=

29. Which method can be used to check if an object contains a specific property in
JavaScript?

A. object.contains(key)
B. object.hasOwnProperty(key)
C. object.include(key)
D. object.getProperty(key)

30. What will the expression [] == ![] return?

A. true
B. false
C. undefined
D. null
31. What does the splice() method do in JavaScript?

A. Adds elements to the end of an array


B. Adds elements to the beginning of an array
C. Removes elements from an array
D. Both adds and removes elements from an array

32. What is the result of console.log(0.1 + 0.2 == 0.3) in JavaScript?

A. true
B. false
C. undefined
D. NaN

33. Which of the following is used to add an event listener to an element in JavaScript?

A. element.addEventListener()
B. element.onEvent()
C. element.bindEvent()
D. element.listenEvent()

34. How do you create a copy of an array in JavaScript?

A. array.copy()
B. array.clone()
C. array.slice()
D. array.duplicate()

35. Which of the following is the correct way to declare a class in JavaScript?

A. class MyClass {}
B. new class MyClass {}
C. class = MyClass {}
D. class MyClass[] {}

36. How do you declare a function in JavaScript?


A. function myFunction() {}
B. def myFunction() {}
C. func myFunction() {}
D. declare function myFunction() {}

37. What is the purpose of bind() in JavaScript?

A. To bind an event to an element


B. To set the value of this for a function
C. To attach a callback function
D. To link two functions together

38. What does the slice() method do in JavaScript?

A. Adds elements to the beginning of an array


B. Returns a portion of an array
C. Removes the last element of an array
D. Modifies the original array in place

39. What will be the result of console.log(1 + "1")?

A. 11
B. 2
C. 1
D. NaN

40. How can you convert a string to lowercase in JavaScript?

A. string.toLowerCase()
B. string.lowerCase()
C. string.makeLower()
D. string.toLower()

41. What will console.log([] == false) output?

A. true
B. false
C. undefined
D. null

42. What is the purpose of the setInterval() method?

A. To stop a function from executing


B. To execute a function repeatedly at specified intervals
C. To delay the execution of a function
D. To repeat a function once

43. Which method can be used to stop the execution of setInterval()?

A. clearInterval()
B. stopInterval()
C. cancelInterval()
D. endInterval()

44. What is the output of console.log("10" - 5)?

A. 10
B. 5
C. 15
D. NaN

45. How can you declare a JavaScript variable that is globally scoped inside a function?

A. global var myVar;


B. this.myVar = value;
C. var myVar = value;
D. window.myVar = value;

46. Which method is used to search for a substring within a string in JavaScript?

A. indexOf()
B. substring()
C. search()
D. includes()
47. What does the delete operator do in JavaScript?

A. Deletes a variable
B. Deletes a property from an object
C. Deletes an element from an array
D. Deletes a function

48. What is the default value of a JavaScript variable that is declared but not assigned a
value?

A. 0
B. null
C. undefined
D. NaN

49. Which of the following is an example of a falsy value in JavaScript?

A. "hello"
B. 1
C. true
D. "" (empty string)

50. Which of the following methods is used to parse a query string into an object in
JavaScript?

A. URLSearchParams
B. queryParser()
C. parseQueryString()
D. getQueryParams()
GOOD LUCK! AIM HIGH! BE BRAVE!

You might also like