Skip to content

Latest commit

 

History

History
324 lines (265 loc) · 10.4 KB

n1aq.md

File metadata and controls

324 lines (265 loc) · 10.4 KB

Stars Badge Forks Badge Pull Requests Badge Issues Badge GitHub contributors Visitors

Don't forget to hit the ⭐ if you like this repo.

JavaScript: Fundamental

Set A

Please answer the following 50 multiple-choice questions to test your knowledge in JavaScript fundamentals. You must place your answer file in the submission folder. Within the submission/Q1/set_a folder, create a folder called your github_id.

  1. What is JavaScript primarily used for?

    • a) Creating stylish webpage layouts
    • b) Adding interactivity to websites
    • c) Storing and managing databases
    • d) Designing server infrastructure
  2. Which keyword is used to declare a variable in JavaScript?

    • a) var
    • b) let
    • c) const
    • d) All of the above
  3. Which data type is not supported in JavaScript?

    • a) Numbers
    • b) Strings
    • c) Booleans
    • d) Characters
  4. What is the result of typeof null in JavaScript?

    • a) "null"
    • b) "object"
    • c) "undefined"
    • d) "string"
  5. How do you add a comment in JavaScript?

    • a) // This is a comment
    • b) /* This is a comment */
    • c) <!-- This is a comment -->
    • d) # This is a comment
  6. Which operator is used for concatenating strings in JavaScript?

    • a) +
    • b) -
    • c) *
    • d) /
  7. What is the output of 2 + "2" in JavaScript?

    • a) 4
    • b) "22"
    • c) "4"
    • d) NaN
  8. Which statement is used to exit a loop in JavaScript?

    • a) break
    • b) continue
    • c) return
    • d) exit
  9. What does the document.getElementById() method in JavaScript do?

    • a) Retrieves an element by its class name
    • b) Retrieves an element by its tag name
    • c) Retrieves an element by its id
    • d) Retrieves an element by its attribute
  10. Which function is used to convert a string to an integer in JavaScript?

    • a) parseInt()
    • b) parseFloat()
    • c) toFixed()
    • d) toString()
  11. How do you declare a function in JavaScript?

    • a) function myFunction() {}
    • b) var myFunction() {}
    • c) const myFunction() {}
    • d) let myFunction() {}
  12. What is the result of 5 == "5" in JavaScript?

    • a) true
    • b) false
    • c) undefined
    • d) NaN
  13. Which method is used to remove the last element from an array in JavaScript?

    • a) pop()
    • b) push()
    • c) shift()
    • d) unshift()
  14. What does the setTimeout() function do in JavaScript?

    • a) Pauses the execution of the code for a specified duration
    • b) Executes a function after a specified delay
    • c) Adds an event listener to an element
    • d) Modifies the style of an element
  15. What is the purpose of the this keyword in JavaScript?

    • a) Refers to the current object or context
    • b) Declares a new variable
    • c) Defines a JavaScript class
    • d) Accesses an external API
  16. How do you check the length of an array in JavaScript?

    • a) length()
    • b) count()
    • c) size()
    • d) length
  17. Which method is used to convert a JavaScript object to a JSON string?

    • a) parse()
    • b) stringify()
    • c) convert()
    • d) serialize()
  18. What does the NaN value represent in JavaScript?

    • a) "Not a Number"
    • b) "Null and Notable"
    • c) "Negative Arithmetic Number"
    • d) "No Action Necessary"
  19. How do you create a new object in JavaScript?

    • a) new Object()
    • b) createObject()
    • c) Object.create()
    • d) All of the above
  20. Which keyword is used to throw an exception in JavaScript?

    • a) exception
    • b) error
    • c) throw
    • d) catch
  21. What is the output of typeof [] in JavaScript?

    • a) "array"
    • b) "object"
    • c) "array-object"
    • d) "undefined"
  22. Which operator is used to check for strict equality in JavaScript?

    • a) ==
    • b) !=
    • c) ===
    • d) !==
  23. What does the splice() method do in JavaScript?

    • a) Adds elements to the beginning of an array
    • b) Removes elements from an array
    • c) Sorts the elements of an array
    • d) Converts an array to a string
  24. Which method is used to add a new element to the end of an array in JavaScript?

    • a) push()
    • b) pop()
    • c) shift()
    • d) unshift()
  25. How do you access the length of a string in JavaScript?

    • a) length()
    • b) size()
    • c) count()
    • d) length
  26. Which method is used to convert a string to uppercase in JavaScript?

    • a) toUpperCase()
    • b) toLowerCase()
    • c) trim()
    • d) charAt()
  27. What does the addEventListener() method do in JavaScript?

    • a) Modifies the style of an element
    • b) Removes an event listener from an element
    • c) Adds an event listener to an element
    • d) Retrieves an element by its id
  28. How do you round a number to the nearest integer in JavaScript?

    • a) round()
    • b) floor()
    • c) ceil()
    • d) toFixed()
  29. What is the purpose of the map() method in JavaScript?

    • a) Iterates over the elements of an array and performs a callback function on each element
    • b) Removes elements from an array based on a specified condition
    • c) Sorts the elements of an array in ascending order
    • d) Converts an array to a string
  30. Which operator is used to access a property of an object in JavaScript?

    • a) :
    • b) .
    • c) =>
    • d) @
  31. What is the output of console.log(typeof NaN) in JavaScript?

    • a) "number"
    • b) "undefined"
    • c) "NaN"
    • d) "object"
  32. How do you convert a JavaScript object to an array?

    • a) Object.values()
    • b) Object.keys()
    • c) Object.entries()
    • d) All of the above
  33. What does the substring() method do in JavaScript?

    • a) Extracts a section of a string and returns a new string
    • b) Removes leading and trailing spaces from a string
    • c) Converts a string to uppercase
    • d) Converts a string to lowercase
  34. Which method is used to sort the elements of an array in JavaScript?

    • a) sort()
    • b) reverse()
    • c) concat()
    • d) slice()
  35. How do you convert a string to an array in JavaScript?

    • a) split()
    • b) join()
    • c) concat()
    • d) splice()
  36. What is the output of console.log(2 + 2 + "2") in JavaScript?

    • a) "4"
    • b) "22"
    • c) "222"
    • d) "NaN"
  37. What is the purpose of the reduce() method in JavaScript?

    • a) Applies a callback function against an accumulator and each element in an array to reduce it to a single value
    • b) Filters the elements of an array based on a specified condition
    • c) Adds new elements to the beginning of an array
    • d) Reverses the order of the elements in an array
  38. How do you check if a variable is an array in JavaScript?

    • a) Array.isArray()
    • b) typeof
    • c) instanceof
    • d) isArray()
  39. Which method is used to remove leading and trailing spaces from a string in JavaScript?

    • a) trim()
    • b) toUpperCase()
    • c) toLowerCase()
    • d) charAt()
  40. What does the toFixed() method do in JavaScript?

    • a) Returns the specified number of decimal places as a string
    • b) Rounds a number to the nearest integer
    • c) Returns the square root of a number
    • d) Returns the absolute value of a number
  41. How do you access the value of an input field in JavaScript?

    • a) document.getValue()
    • b) inputField.value
    • c) inputField.getValue()
    • d) document.getElement(inputField).value
  42. Which method is used to find the index of a specified value in an array in JavaScript?

    • a) indexOf()
    • b) findIndex()
    • c) search()
    • d) includes()
  43. What is the output of console.log(2 * "2") in JavaScript?

    • a) 4
    • b) "4"
    • c) "22"
    • d) NaN
  44. How do you convert a number to a string in JavaScript?

    • a) String()
    • b) Number.toString()
    • c) parseInt()
    • d) toFixed()
  45. What does the Math.random() function do in JavaScript?

    • a) Returns a random integer between 0 and 1
    • b) Generates a random number between a specified range
    • c) Returns the square root of a number
    • d) Rounds a number to the nearest integer
  46. Which method is used to remove an event listener from an element in JavaScript?

    • a) removeEventListener()
    • b) addEventListener()
    • c) getElementById()
    • d) querySelector()
  47. How do you convert a string to lowercase in JavaScript?

    • a) toLowerCase()
    • b) toUpperCase()
    • c) trim()
    • d) charAt()
  48. What is the output of console.log(5 > 2 && 3 < 6) in JavaScript?

    • a) true
    • b) false
    • c) undefined
    • d) NaN
  49. Which method is used to find the highest value in an array in JavaScript?

    • a) Math.max()
    • b) Math.min()
    • c) findMax()
    • d) findMin()
  50. How do you convert a string to uppercase in JavaScript?

    • a) toUpperCase()
    • b) toLowerCase()
    • c) trim()
    • d) charAt()

Contribution 🛠️

Please create an Issue for any improvements, suggestions or errors in the content.

You can also contact me using Linkedin for any other queries or feedback.

Visitors