Skip to content

Latest commit

 

History

History
394 lines (320 loc) · 10.9 KB

n1bq.md

File metadata and controls

394 lines (320 loc) · 10.9 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 B

You must place your answer file in the submission folder. Within the submission/Q1/set_b folder, create a folder called your github_id.

  1. Which keyword is used to declare a variable in JavaScript?

    • a) var
    • b) let
    • c) const
    • d) All of the above
  2. What is the correct way to comment a single line of code in JavaScript?

    • a) /* Comment */
    • b) <!-- Comment -->
    • c) // Comment
    • d) # Comment
  3. What is the output of the following code snippet?

    console.log(2 + "2");
    • a) 4
    • b) "4"
    • c) 22
    • d) NaN
  4. Which data type represents a sequence of characters in JavaScript?

    • a) String
    • b) Number
    • c) Boolean
    • d) Object
  5. How do you declare a constant variable in JavaScript?

    • a) var
    • b) let
    • c) const
    • d) constant
  6. What is the output of the following code snippet?

    console.log(10 > 5 && 5 < 3);
    • a) true
    • b) false
    • c) NaN
    • d) SyntaxError
  7. How do you define a function in JavaScript?

    • a) func myFunction() {}
    • b) function: myFunction() {}
    • c) function myFunction() {}
    • d) def myFunction() {}
  8. What is the purpose of the addEventListener method in JavaScript?

    • a) To add comments to the code
    • b) To execute a function when an event occurs
    • c) To modify the style of an element
    • d) To declare a variable
  9. What is the output of the following code snippet?

    var x = 5;
    console.log(x++);
    • a) 5
    • b) 6
    • c) 4
    • d) NaN
  10. Which JavaScript keyword is used to exit a loop iteration?

    • a) exit
    • b) continue
    • c) break
    • d) return
  11. What does the acronym "DOM" stand for in JavaScript?

    • a) Document Object Model
    • b) Data Object Model
    • c) Dynamic Object Model
    • d) Document Order Model
  12. How do you select an HTML element using its id in JavaScript?

    • a) selectElementById()
    • b) getElement()
    • c) querySelector()
    • d) getElementById()
  13. What is the purpose of the try...catch statement in JavaScript?

    • a) To declare a new function
    • b) To handle runtime errors
    • c) To perform arithmetic operations
    • d) To modify the DOM
  14. What is the output of the following code snippet?

    console.log(typeof undefined);
    • a) "undefined"
    • b) "null"
    • c) "boolean"
    • d) "number"
  15. Which of the following is an example of a JavaScript library?

    • a) React
    • b) JavaFX
    • c) Django
    • d) Flask
  16. What is the correct syntax to access a property of an object in JavaScript?

    • a) object.property
    • b) object[property]
    • c) object->property
    • d) object::property
  17. What is the output of the following code snippet?

    var arr = [1, 2, 3, 4, 5];
    console.log(arr.length);
    • a) 1
    • b) 5
    • c) 4
    • d) undefined
  18. How do you convert a string to lowercase in JavaScript?

    • a) toLowerCase()
    • b) toLower()
    • c) lowerCase()
    • d) convertToLower()
  19. Which method is used to add a new element at the end of an array in JavaScript?

    • a) push()
    • b) pop()
    • c) shift()
    • d) unshift()
  20. What is the output of the following code snippet?

    console.log(typeof NaN);
    • a) "number"
    • b) "undefined"
    • c) "NaN"
    • d) "string"
  21. Which JavaScript method is used to remove the first occurrence of a specific element from an array?

    • a) shift()
    • b) splice()
    • c) slice()
    • d) remove()
  22. What is the purpose of the setTimeout function in JavaScript?

    • a) To delay the execution of a function
    • b) To change the style of an element
    • c) To perform mathematical calculations
    • d) To validate form inputs
  23. What is the output of the following code snippet?

    var x = 10;
    var y = "5";
    console.log(x + y);
    • a) "105"
    • b) "15"
    • c) "NaN"
    • d) SyntaxError
  24. Which event occurs when a user clicks on an HTML element?

    • a) onload
    • b) onchange
    • c) onclick
    • d) onmouseover
  25. What is the purpose of the innerHTML property in JavaScript?

    • a) To change the HTML content of an element
    • b) To add a new class to an element
    • c) To select an element by its ID
    • d) To execute a function when an event occurs
  26. What is the output of the following code snippet?

    var num = 10;
    console.log(num.toFixed(2));
    • a) 10
    • b) 10.00
    • c) NaN
    • d) SyntaxError
  27. How do you check if a variable is an array in JavaScript?

    • a) Array.isArray(variable)
    • b) variable.isArray()
    • c) typeof variable === "array"
    • d) variable instanceof Array
  28. What is the purpose of the parseInt function in JavaScript?

    • a) To convert a string to an integer
    • b) To format a number with decimal places
    • c) To calculate the square root of a number
    • d) To sort elements in an array
  29. What is the output of the following code snippet?

    console.log("2" + 2);
    • a) 4
    • b) "22"
    • c) 2
    • d) "2"
  30. Which method is used to remove the last element from an array in JavaScript?

    • a) push()
    • b) pop()
    • c) shift()
    • d) unshift()
  31. What is the purpose of the querySelector method in JavaScript?

    • a) To select the first element that matches a CSS selector
    • b) To add a new element to the DOM
    • c) To remove an element from the DOM
    • d) To modify the style of an element
  32. What is the output of the following code snippet?

    console.log(0.1 + 0.2 === 0.3);
    • a) true
    • b) false
    • c) NaN
    • d) SyntaxError
  33. How do you access the length of an array in JavaScript?

    • a) array.length
    • b) array.size()
    • c) array.length()
    • d) array.size
  34. What is the purpose of the parseFloat function in JavaScript?

    • a) To convert a string to a floating-point number
    • b) To convert a number to a string
    • c) To round a number to the nearest integer
    • d) To calculate the square root of a number
  35. What is the output of the following code snippet?

    var x = 10;
    var y = 5;
    console.log(x += y);
    • a) 5
    • b) 10
    • c) 15
    • d) SyntaxError
  36. How do you create a new object in JavaScript?

    • a) new Object()
    • b) Object.create()
    • c) {}
    • d) All of the above
  37. What is the output of the following code snippet?

    console.log(Boolean(""));
    • a) true
    • b) false
    • c) null
    • d) undefined
  38. Which JavaScript method is used to remove the last element from an array?

    • a) shift()
    • b) splice()
    • c) slice()
    • d) pop()
  39. What is the purpose of the toUpperCase method in JavaScript?

    • a) To convert a string to uppercase letters
    • b) To convert a string to lowercase letters
    • c) To split a string into an array of substrings
    • d) To remove whitespace from the beginning and end of a string
  40. What is the output of the following code snippet?

    console.log(10 % 3);
    • a) 3
    • b) 1
    • c) 0
    • d) 10
  41. How do you access the first element of an array in JavaScript?

    • a) array[0]
    • b) array.first()
    • c) array.getElement(0)
    • d) array.firstElement()
  42. What is the purpose of the split method in JavaScript?

    • a) To convert a string to an array of substrings
    • b) To join two or more arrays into one
    • c) To merge two or more objects into one
    • d) To split an element into multiple elements
  43. What is the output of the following code snippet?

    console.log(Math.floor(3.9));
    • a) 3
    • b) 4
    • c) 3.9
    • d) SyntaxError
  44. How do you remove an event listener in JavaScript?

    • a) removeEventListener()
    • b) detachEvent()
    • c) removeEvent()
    • d) unbindEvent()
  45. What is the purpose of the Math.random method in JavaScript?

    • a) To generate a random number between 0 and 1
    • b) To round a number to the nearest integer
    • c) To calculate the square root of a number
    • d) To calculate the absolute value of a number
  46. What is the output of the following code snippet?

    console.log(10 + "5");
    • a) 15
    • b) "15"
    • c) 105
    • d) SyntaxError
  47. Which JavaScript method is used to concatenate two or more arrays?

    • a) concat()
    • b) push()
    • c) join()
    • d) merge()
  48. What is the purpose of the toFixed method in JavaScript?

    • a) To format a number with a specified number of decimal places
    • b) To convert a number to a string
    • c) To check if a value is a number
    • d) To calculate the square root of a number
  49. What is the output of the following code snippet?

    console.log(true && false);
    • a) true
    • b) false
    • c) NaN
    • d) SyntaxError
  50. How do you access the value of a checkbox in JavaScript?

    • a) checkbox.value
    • b) checkbox.checked
    • c) checkbox.selected
    • d) checkbox.state

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