MCQs Of Day 30: JavaScript Project - To-Do List Application

Rashmi Mishra
0

  MCQs Of Day 29: JavaScript Project - To-Do List Application

MCQs

1.   What does the addEventListener() method do in JavaScript?

o    A) It listens for user input

o    B) It attaches an event handler to a specified element

o    C) It modifies an HTML element

o    D) It updates the browser window

o    Explanation: addEventListener() attaches an event handler to an HTML element, listening for specific events like clicks or keyboard input.


2.   What is the purpose of localStorage in JavaScript?

o    A) To store session data for the current session only

o    B) To store data persistently across browser sessions

o    C) To store data on the server

o    D) To prevent data from being deleted

o    Explanation: localStorage stores data persistently on the user's browser, even across browser sessions.


3.   Which method is used to save an object to localStorage in JavaScript?

o    A) localStorage.save()

o    B) localStorage.set()

o    C) localStorage.setItem()

o    D) localStorage.saveItem()

o    Explanation: localStorage.setItem() is used to save data in localStorage.


4.   Which of the following methods would you use to remove an item from localStorage?

o    A) localStorage.removeItem()

o    B) localStorage.deleteItem()

o    C) localStorage.clear()

o    D) localStorage.dropItem()

o    Explanation: localStorage.removeItem() removes a specific item from localStorage.


5.   How can you check if a task is marked as completed in the to-do list?

o    A) task.completed === true

o    B) task.isCompleted === 1

o    C) task.checked()

o    D) task.complete()

o    Explanation: To check if a task is completed, use task.completed === true.


6.   Which JavaScript method is used to add a new task to an array?

o    A) push()

o    B) add()

o    C) insert()

o    D) append()

o    Explanation: The push() method adds a new item to the end of an array.


7.   What is the purpose of the prompt() method in JavaScript?

o    A) It creates a new HTML element

o    B) It asks the user to input a value through a pop-up window

o    C) It deletes an element

o    D) It alerts the user with a message

o    Explanation: prompt() displays a dialog box that asks the user to input a value.


8.   How can you check if an HTML element exists before manipulating it in JavaScript?

o    A) if (element == null)

o    B) if (element === undefined)

o    C) if (element)

o    D) if (element != false)

o    Explanation: if (element) checks if the element exists, and if so, the code inside the block is executed.


9.   Which method would you use to add a new task to the HTML list element (ul or ol)?

o    A) document.createElement()

o    B) document.addElement()

o    C) document.appendChild()

o    D) document.insertElement()

o    Explanation: document.createElement() creates a new HTML element, and appendChild() adds it to the parent.


10.                     Which of the following is used to mark a task as completed in the to-do list?

  • A) task.completed = true
  • B) task.isDone = 1
  • C) task.finish()
  • D) task.done()
  • Explanation: task.completed = true sets the task's completed property to true.

11.                     How do you delete a task from the tasks array in JavaScript?

  • A) tasks.remove(index)
  • B) tasks.delete(index)
  • C) tasks.splice(index, 1)
  • D) tasks.removeItem(index)
  • Explanation: tasks.splice(index, 1) removes an element from the array at the specified index.

12.                     What is the default behavior of a button element in a form?

  • A) It refreshes the page
  • B) It submits the form
  • C) It deletes a task
  • D) It logs the user out
  • Explanation: A button element inside a form submits the form by default.

13.                     What method is used to convert a string into an array in JavaScript?

  • A) split()
  • B) array()
  • C) toArray()
  • D) stringArray()
  • Explanation: The split() method splits a string into an array based on a separator.

14.                     What is the main function of JSON.stringify() in JavaScript?

  • A) To parse a JSON string
  • B) To convert a JavaScript object into a JSON string
  • C) To convert a string into an object
  • D) To save a JSON string to localStorage
  • Explanation: JSON.stringify() converts a JavaScript object into a JSON string.

15.                     Which of the following is true about the filter() method in JavaScript?

  • A) It removes elements from an array
  • B) It creates a new array with elements that pass a test
  • C) It sorts an array
  • D) It modifies the original array
  • Explanation: The filter() method creates a new array containing elements that pass a test implemented in a callback function.

16.                     What does the clear() method do in localStorage?

  • A) Clears all data in localStorage
  • B) Clears the page content
  • C) Clears the console logs
  • D) Clears cookies
  • Explanation: The clear() method removes all data from localStorage.

17.                     How do you mark a task as incomplete after it has been completed?

  • A) task.completed = false
  • B) task.setCompleted(false)
  • C) task.removeCompleted()
  • D) task.status = 'not completed'
  • Explanation: Setting task.completed = false marks the task as incomplete.

18.                     Which of the following is an example of accessing the value of a text input in JavaScript?

  • A) input.getValue()
  • B) input.text
  • C) input.value
  • D) input.textContent
  • Explanation: input.value gets the current value of an input field.

19.                     What is the purpose of taskInput.value = "" in JavaScript?

  • A) It resets the form
  • B) It clears the value of an input field
  • C) It sets a default value for the input
  • D) It saves the task to localStorage
  • Explanation: taskInput.value = "" clears the current value of the input field.

20.                     Which HTML element is used to create an unordered list?

  • A) <ol>
  • B) <ul>
  • C) <list>
  • D) <ul-list>
  • Explanation: <ul> creates an unordered list in HTML.

21.                     How do you append a new task to the list in the DOM?

  • A) taskList.add(task)
  • B) taskList.innerHTML += task
  • C) taskList.appendChild(task)
  • D) taskList.insert(task)
  • Explanation: taskList.appendChild(task) appends a new task to the task list.

22.                     Which of the following method is used to parse JSON data in JavaScript?

  • A) JSON.decode()
  • B) JSON.parse()
  • C) JSON.encode()
  • D) JSON.load()
  • Explanation: JSON.parse() parses a JSON string into a JavaScript object.

23.                     How do you handle a click event for a button in JavaScript?

  • A) button.onClick()
  • B) button.addEventListener('click', handler)
  • C) button.click()
  • D) button.trigger('click')
  • Explanation: button.addEventListener('click', handler) listens for a click event on the button and executes the handler function.

24.                     What is the output of the following code?

javascript

Copy code

let tasks = [{ text: 'Task 1' }, { text: 'Task 2' }];

console.log(tasks.length);

  • A) 2
  • B) undefined
  • C) 3
  • D) Task 1
  • Explanation: tasks.length outputs the number of elements in the tasks array, which is 2.

25.                     Which of the following is a correct way to update the value of a task?

  • A) task.text = 'New Task'
  • B) task.update('New Task')
  • C) task.setValue('New Task')
  • D) task.modify('New Task')
  • Explanation: task.text = 'New Task' updates the text of the task.

This set of MCQs will help in assessing a student's understanding of JavaScript concepts like DOM manipulation, localStorage, events, and array methods used in building a To-Do List application. Feel free to ask if you need more questions or details!

4o mini

You said:

yes

ChatGPT said:

ChatGPT

Here is a continuation of the 100 multiple-choice questions (MCQs) based on the JavaScript To-Do List Application project, with explanations for each question:


26.                     What does the JSON.parse() method do in JavaScript?

  • A) Converts a JavaScript object into a JSON string
  • B) Parses a JSON string into a JavaScript object
  • C) Parses a JavaScript object into a string
  • D) Converts a string into an array
  • Explanation: JSON.parse() is used to convert a JSON string into a JavaScript object.

27.                     Which of the following is the correct syntax to listen for a click event on a button element?

  • A) button.addEventListener('click', function)
  • B) button.onClick(function)
  • C) button.addEventListener(function, 'click')
  • D) button.click('event', function)
  • Explanation: button.addEventListener('click', function) is the correct syntax to attach a click event listener.

28.                     How can you store an array of tasks in localStorage?

  • A) localStorage.setItem('tasks', tasks)
  • B) localStorage.setItem('tasks', JSON.stringify(tasks))
  • C) localStorage.addItem('tasks', tasks)
  • D) localStorage.push('tasks', tasks)
  • Explanation: localStorage.setItem('tasks', JSON.stringify(tasks)) stores the array after converting it to a string using JSON.stringify().

29.                     Which JavaScript method is used to remove the last element from an array?

  • A) pop()
  • B) shift()
  • C) remove()
  • D) delete()
  • Explanation: pop() removes the last element from an array.

30.                     What does the JSON.stringify() method do in JavaScript?

  • A) Converts a JavaScript object to a string
  • B) Parses a JSON string into a JavaScript object
  • C) Stores data into localStorage
  • D) Creates an array from a JSON string
  • Explanation: JSON.stringify() converts a JavaScript object into a JSON string.

31.                     How can you add an event listener to a task element when it is clicked?

  • A) task.addEventListener('click', function)
  • B) task.onclick = function
  • C) task.listen('click', function)
  • D) task.eventListener('click', function)
  • Explanation: task.addEventListener('click', function) adds a click event listener to the task element.

32.                     What is the purpose of taskList.appendChild(newTaskElement) in JavaScript?

  • A) It appends a new task to the taskList array
  • B) It adds a new task element to the DOM under the taskList
  • C) It deletes the task from the list
  • D) It replaces the content of the taskList element
  • Explanation: taskList.appendChild(newTaskElement) adds a new task element to the taskList in the DOM.

33.                     What does the splice() method do in JavaScript arrays?

  • A) Adds items to the array
  • B) Removes or replaces elements in the array
  • C) Sorts the array
  • D) Converts an array into a string
  • Explanation: splice() is used to remove or replace elements from an array.

34.                     How do you prevent the default behavior of an event in JavaScript?

  • A) event.preventDefault()
  • B) event.stopPropagation()
  • C) event.stopDefault()
  • D) event.cancelDefault()
  • Explanation: event.preventDefault() prevents the default action associated with an event (e.g., form submission or link navigation).

35.                     What is the correct way to store a task in the localStorage after marking it as completed?

  • A) localStorage.setItem('tasks', JSON.stringify(tasks))
  • B) tasks.save()
  • C) localStorage.store('tasks', tasks)
  • D) tasks.store()
  • Explanation: localStorage.setItem('tasks', JSON.stringify(tasks)) stores the tasks in localStorage after converting them into a JSON string.

36.                     How do you access an element with the id taskInput in JavaScript?

  • A) document.getElementById('taskInput')
  • B) document.querySelector('#taskInput')
  • C) document.getElementById('#taskInput')
  • D) Both A and B
  • Explanation: Both document.getElementById('taskInput') and document.querySelector('#taskInput') can be used to access an element with the specified ID.

37.                     What is the purpose of using innerHTML in JavaScript?

  • A) To change the style of an element
  • B) To set or get the HTML content inside an element
  • C) To create a new element
  • D) To append a new event listener
  • Explanation: innerHTML is used to set or get the HTML content inside an element.

38.                     Which of the following methods is used to create a new HTML element in JavaScript?

  • A) document.createElement()
  • B) document.addElement()
  • C) document.insertElement()
  • D) document.newElement()
  • Explanation: document.createElement() is used to create a new HTML element.

39.                     Which of the following is the correct way to store the task name in the localStorage?

  • A) localStorage.setItem('taskName', task.name)
  • B) localStorage.addItem('taskName', task.name)
  • C) localStorage.store('taskName', task.name)
  • D) task.name.storeIn('localStorage')
  • Explanation: localStorage.setItem('taskName', task.name) stores the task name in localStorage.

40.                     How do you update the value of an input field in JavaScript?

  • A) input.setValue('new value')
  • B) input.value = 'new value'
  • C) input.setText('new value')
  • D) input.setTextContent('new value')
  • Explanation: input.value = 'new value' is used to update the value of an input field.

41.                     What is the purpose of localStorage.getItem() in JavaScript?

  • A) To store data in localStorage
  • B) To remove an item from localStorage
  • C) To retrieve a stored item from localStorage
  • D) To clear all data in localStorage
  • Explanation: localStorage.getItem() is used to retrieve a stored item from localStorage.

42.                     Which of the following JavaScript methods adds a new task to an array?

  • A) tasks.push()
  • B) tasks.insert()
  • C) tasks.append()
  • D) tasks.add()
  • Explanation: tasks.push() adds a new element to the end of the tasks array.

43.                     How can you handle a click event for the "delete task" button?

  • A) deleteButton.onclick = deleteTask
  • B) deleteButton.addEventListener('click', deleteTask)
  • C) Both A and B
  • D) deleteButton.trigger('click')
  • Explanation: Both deleteButton.onclick = deleteTask and deleteButton.addEventListener('click', deleteTask) can handle the click event.

44.                     What does the console.log() method do in JavaScript?

  • A) Displays a dialog box to the user
  • B) Logs a message to the console for debugging
  • C) Displays a confirmation dialog
  • D) Displays a message on the webpage
  • Explanation: console.log() logs a message to the console for debugging purposes.

45.                     What is the correct way to update the task's completion status?

  • A) task.isCompleted = true
  • B) task.completed = false
  • C) task.done = 'completed'
  • D) task.setCompleted(true)
  • Explanation: task.completed = true updates the task's completion status.

46.                     Which JavaScript method is used to convert an object to a JSON string?

  • A) JSON.parse()
  • B) JSON.stringify()
  • C) JSON.convert()
  • D) JSON.objectify()
  • Explanation: JSON.stringify() converts an object to a JSON string.

47.                     What is the correct way to delete a task from the DOM?

  • A) task.remove()
  • B) task.delete()
  • C) task.deleteChild()
  • D) task.removeChild()
  • Explanation: task.remove() deletes the task element from the DOM.

48.                     How do you trigger an event for a task element in JavaScript?

  • A) task.trigger()
  • B) task.dispatchEvent()
  • C) task.event()
  • D) task.activate()
  • Explanation: task.dispatchEvent() triggers an event for the task element.

49.                     How do you check if a key exists in localStorage?

  • A) localStorage.contains('key')
  • B) localStorage.has('key')
  • C) localStorage.getItem('key') !== null
  • D) localStorage.exists('key')
  • Explanation: localStorage.getItem('key') !== null checks if the key exists in localStorage.

50.                     Which of the following methods can be used to clear all tasks from localStorage?

  • A) localStorage.clear()
  • B) localStorage.removeAll()
  • C) localStorage.remove()
  • D) localStorage.reset()
  • Explanation: localStorage.clear() removes all items from localStorage.

This completes a set of 50 MCQs, and you can create additional questions to reach 100 as needed. The explanations focus on the essential JavaScript concepts related to the To-Do List application, such as DOM manipulation, event handling, array methods, and localStorage functionality.

2/2

4o mini

You said:

next

ChatGPT said:

ChatGPT

Here is the continuation of the multiple-choice questions (MCQs) based on the JavaScript To-Do List Application project, with explanations for each question:


51.                     Which method is used to check if a task exists in the tasks array?

  • A) tasks.includes()
  • B) tasks.exists()
  • C) tasks.contains()
  • D) tasks.find()
  • Explanation: tasks.includes() checks if a specific task exists in the array.

52.                     How do you retrieve all tasks from localStorage in JavaScript?

  • A) localStorage.getItem('tasks')
  • B) localStorage.retrieve('tasks')
  • C) localStorage.fetch('tasks')
  • D) localStorage.getAll('tasks')
  • Explanation: localStorage.getItem('tasks') is used to retrieve a specific item (in this case, tasks) from localStorage.

53.                     What is the default value of a newly created HTML input element’s value property?

  • A) null
  • B) undefined
  • C) "" (empty string)
  • D) "0"
  • Explanation: The default value of an input element’s value property is "" (empty string).

54.                     What will taskList.children return in JavaScript?

  • A) A string containing all child elements of taskList
  • B) An array of all child elements of taskList
  • C) A NodeList of all child elements of taskList
  • D) A list of child element IDs
  • Explanation: taskList.children returns a NodeList of all child elements of taskList.

55.                     Which of the following is used to loop through each task in an array in JavaScript?

  • A) forEach()
  • B) map()
  • C) for()
  • D) while()
  • Explanation: forEach() is used to loop through each element in an array.

56.                     What is the result of task.completed = !task.completed; in JavaScript?

  • A) It toggles the completed status of a task.
  • B) It sets the completed status to false.
  • C) It deletes the completed property of a task.
  • D) It adds a new completed property to the task.
  • Explanation: task.completed = !task.completed; toggles the completed status (true to false and vice versa).

57.                     How do you add a new task to the taskList in the DOM?

  • A) taskList.appendChild(newTask)
  • B) taskList.addChild(newTask)
  • C) taskList.insert(newTask)
  • D) taskList.addElement(newTask)
  • Explanation: taskList.appendChild(newTask) adds a new task element to the taskList in the DOM.

58.                     Which method is used to remove an item from localStorage?

  • A) localStorage.removeItem()
  • B) localStorage.deleteItem()
  • C) localStorage.remove()
  • D) localStorage.clear()
  • Explanation: localStorage.removeItem() removes a specific item from localStorage.

59.                     Which event is used to detect a change in the value of an input field?

  • A) input.onchange
  • B) input.oninput
  • C) input.onchange()
  • D) Both A and B
  • Explanation: input.onchange and input.oninput are used to detect when the value of an input field changes.

60.                     Which of the following is the correct way to access a class in JavaScript?

  • A) document.getElementsByClass('className')
  • B) document.getElementByClass('className')
  • C) document.getElementsByClassName('className')
  • D) document.querySelector('.className')
  • Explanation: document.getElementsByClassName('className') is used to select elements by their class name.

61.                     What is the purpose of event.stopPropagation() in JavaScript?

  • A) It stops the event from being handled by the current element.
  • B) It prevents the event from being passed to the parent elements.
  • C) It prevents the default action of the event.
  • D) It allows the event to propagate to all other elements.
  • Explanation: event.stopPropagation() prevents the event from propagating (bubbling) to parent elements.

62.                     Which JavaScript method is used to remove an element from an array?

  • A) remove()
  • B) shift()
  • C) pop()
  • D) splice()
  • Explanation: splice() is used to remove elements from an array.

63.                     Which function is used to create a new task item in the To-Do list application?

  • A) createTask()
  • B) addTask()
  • C) newTask()
  • D) saveTask()
  • Explanation: Typically, addTask() or createTask() is used to add a new task in the application.

64.                     What will the following code snippet do? tasks.push(newTask)

  • A) Adds newTask at the beginning of the tasks array
  • B) Removes newTask from the tasks array
  • C) Adds newTask at the end of the tasks array
  • D) Replaces the first item in the tasks array with newTask
  • Explanation: tasks.push(newTask) adds newTask to the end of the tasks array.

65.                     Which of the following properties is used to set the inner text of an HTML element?

  • A) element.textContent
  • B) element.innerHTML
  • C) element.innerText
  • D) All of the above
  • Explanation: All the above properties (textContent, innerHTML, innerText) can be used to modify the content of an element, but textContent and innerText are commonly used for text.

66.                     What is the purpose of the DOMContentLoaded event in JavaScript?

  • A) To detect when the page finishes loading all content, including images and styles
  • B) To detect when the page finishes loading HTML
  • C) To listen for user interactions
  • D) To log an error if the page fails to load
  • Explanation: The DOMContentLoaded event is triggered when the HTML content of the page is fully loaded, but before images and other external resources are loaded.

67.                     How do you ensure that the tasks array is updated in localStorage after adding a new task?

  • A) localStorage.setItem('tasks', tasks)
  • B) localStorage.setItem('tasks', JSON.stringify(tasks))
  • C) localStorage.set('tasks', tasks)
  • D) localStorage.push('tasks', tasks)
  • Explanation: localStorage.setItem('tasks', JSON.stringify(tasks)) is the correct way to update the tasks array in localStorage after converting it to a string.

68.                     Which of the following is used to add a task’s title to the HTML list in the To-Do application?

  • A) taskTitle.innerHTML = 'New Task'
  • B) taskTitle.innerText = 'New Task'
  • C) taskTitle.textContent = 'New Task'
  • D) All of the above
  • Explanation: Any of the above (innerHTML, innerText, or textContent) can be used to set the title of a task in HTML.

69.                     How do you iterate over a NodeList in JavaScript?

  • A) Using a for loop
  • B) Using forEach()
  • C) Using map()
  • D) All of the above
  • Explanation: Both for loop and forEach() can be used to iterate over a NodeList.

70.                     What will the following code do? task.removeChild(childTask)

  • A) Remove childTask from the parent element
  • B) Remove childTask from the array
  • C) Remove task from the DOM
  • D) Remove the task's childTask property
  • Explanation: task.removeChild(childTask) removes the childTask element from the parent task element in the DOM.

71.                     How can you check if a task is marked as complete in JavaScript?

  • A) task.completed === true
  • B) task.isComplete()
  • C) task.completed()
  • D) task.status === 'completed'
  • Explanation: task.completed === true checks if the task is marked as complete.

72.                     What does the task.completed = false; code do?

  • A) Marks the task as incomplete
  • B) Marks the task as complete
  • C) Deletes the task from the array
  • D) Adds a completed property to the task
  • Explanation: task.completed = false; marks the task as incomplete.

73.                     How do you edit an existing task in the To-Do list?

  • A) By changing the task's textContent and updating the tasks array
  • B) By removing the task and adding it again
  • C) By changing the task's id
  • D) By adding a new completed property
  • Explanation: To edit a task, you change its textContent (or the relevant property) and update the tasks array accordingly.

74.                     Which of the following methods is used to store data in localStorage?

  • A) localStorage.addItem()
  • B) localStorage.store()
  • C) localStorage.setItem()
  • D) localStorage.save()
  • Explanation: localStorage.setItem() is used to store data in localStorage.

75.                     How do you make a task completed in a To-Do list?

  • A) By updating the task's class to completed
  • B) By setting the task's completed property to true
  • C) By removing the task from the list
  • D) Both A and B
  • Explanation: To mark a task as completed, you typically update the task's class and/or set its completed property to true.

The MCQs above cover important concepts of JavaScript, including DOM manipulation, event handling, array methods, and localStorage, which are critical for building a To-Do list application. These questions can help reinforce the concepts and test students' understanding of the topic.

4o mini

You said:

next

ChatGPT said:

ChatGPT

Here is the continuation of the multiple-choice questions (MCQs) with explanations:


76.                     Which of the following methods is used to parse a JSON string into a JavaScript object?

  • A) JSON.parse()
  • B) JSON.stringify()
  • C) JSON.toObject()
  • D) JSON.convert()
  • Explanation: JSON.parse() is used to parse a JSON string into a JavaScript object.

77.                     What does the following code do: tasks.forEach(task => console.log(task.title));?

  • A) Logs the title of each task in the console
  • B) Adds the title of each task to the DOM
  • C) Updates the title of each task
  • D) Filters tasks based on the title
  • Explanation: This code uses the forEach() method to log the title of each task to the console.

78.                     Which of the following is used to add an event listener for a click event in JavaScript?

  • A) element.addEventListener('click', function)
  • B) element.click()
  • C) element.onClick()
  • D) element.addEvent('click', function)
  • Explanation: element.addEventListener('click', function) is used to add an event listener for the click event.

79.                     Which method is used to convert a JavaScript object into a JSON string?

  • A) JSON.toString()
  • B) JSON.stringify()
  • C) JSON.parse()
  • D) JSON.convert()
  • Explanation: JSON.stringify() is used to convert a JavaScript object into a JSON string.

80.                     What is the main advantage of using localStorage in web development?

  • A) Data is stored permanently on the server
  • B) Data is available to all websites
  • C) Data persists even after the browser is closed
  • D) Data is stored in a remote database
  • Explanation: Data stored in localStorage persists even after the browser is closed.

81.                     How do you remove a task from the DOM?

  • A) task.remove()
  • B) task.delete()
  • C) task.removeChild()
  • D) task.clear()
  • Explanation: task.remove() is used to remove the task element from the DOM.

82.                     What is the correct way to add a new task to the tasks array?

  • A) tasks.push('New Task')
  • B) tasks.add('New Task')
  • C) tasks.insert('New Task')
  • D) tasks.append('New Task')
  • Explanation: tasks.push('New Task') adds a new task to the end of the tasks array.

83.                     Which method is used to update a task’s title in JavaScript?

  • A) task.update()
  • B) task.setTitle()
  • C) task.title = 'New Title'
  • D) task.changeTitle()
  • Explanation: task.title = 'New Title' directly updates the task's title property.

84.                     What happens if you call JSON.parse() on an invalid JSON string?

  • A) It returns null
  • B) It throws an error
  • C) It returns undefined
  • D) It returns the original string
  • Explanation: JSON.parse() throws an error if the provided string is not valid JSON.

85.                     How do you check if an object property exists in JavaScript?

  • A) object.hasProperty('propertyName')
  • B) 'propertyName' in object
  • C) object.contains('propertyName')
  • D) object.exists('propertyName')
  • Explanation: 'propertyName' in object is used to check if the property exists in the object.

86.                     What is the default value of a boolean variable in JavaScript?

  • A) undefined
  • B) null
  • C) false
  • D) true
  • Explanation: The default value of a boolean variable is false.

87.                     Which of the following is used to create a new DOM element in JavaScript?

  • A) document.createElement()
  • B) document.addElement()
  • C) document.newElement()
  • D) document.insertElement()
  • Explanation: document.createElement() is used to create a new DOM element.

88.                     Which of the following methods is used to append a new child element to an existing DOM element?

  • A) parent.appendChild(child)
  • B) parent.addChild(child)
  • C) parent.insertChild(child)
  • D) parent.append(child)
  • Explanation: parent.appendChild(child) appends a new child element to the parent element in the DOM.

89.                     Which of the following is true about JavaScript objects?

  • A) Objects can only have string keys
  • B) Objects can have both string and symbol keys
  • C) Objects cannot have properties with special characters
  • D) Objects can only store primitive data types
  • Explanation: JavaScript objects can have both string and symbol keys.

90.                     Which of the following is used to validate if a variable is an array in JavaScript?

  • A) Array.isArray()
  • B) array.isArray()
  • C) typeof array === 'array'
  • D) array.validate()
  • Explanation: Array.isArray() is used to check if a variable is an array.

91.                     How can you prevent the default action of an event in JavaScript?

  • A) event.preventDefault()
  • B) event.stopDefault()
  • C) event.cancel()
  • D) event.stop()
  • Explanation: event.preventDefault() is used to prevent the default action of an event.

92.                     Which method is used to remove the last element of an array in JavaScript?

  • A) array.remove()
  • B) array.pop()
  • C) array.shift()
  • D) array.delete()
  • Explanation: array.pop() is used to remove the last element from an array.

93.                     Which of the following methods is used to add a new element to the beginning of an array?

  • A) array.unshift()
  • B) array.push()
  • C) array.add()
  • D) array.insert()
  • Explanation: array.unshift() adds a new element to the beginning of an array.

94.                     Which of the following is the correct way to handle events using event delegation?

  • A) Attaching event listeners to each child element
  • B) Attaching a single event listener to a parent element
  • C) Using setInterval() to handle events
  • D) Using requestAnimationFrame() to handle events
  • Explanation: Event delegation involves attaching a single event listener to a parent element, which then handles events for child elements.

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

  • A) To convert a JavaScript object into a JSON string
  • B) To parse a JSON string into a JavaScript object
  • C) To store data in the localStorage
  • D) To send data to a server
  • Explanation: JSON.stringify() is used to convert a JavaScript object into a JSON string.

96.                     Which method is used to select an element by its ID in JavaScript?

  • A) document.getElementById()
  • B) document.getElementsByClassName()
  • C) document.querySelectorAll()
  • D) document.getById()
  • Explanation: document.getElementById() is used to select an element by its ID.

97.                     What is the difference between == and === in JavaScript?

  • A) == compares values only, === compares both values and types
  • B) == compares both values and types, === compares values only
  • C) == is for primitive data types, === is for objects
  • D) There is no difference
  • Explanation: == compares only values, while === compares both values and types.

98.                     Which of the following statements is true about localStorage?

  • A) It stores data permanently across sessions
  • B) It stores data temporarily during a session
  • C) It stores data only for one page load
  • D) It stores data on the server
  • Explanation: localStorage stores data permanently across sessions until explicitly removed.

99.                     What is the default data type of a value in localStorage?

  • A) String
  • B) Array
  • C) Object
  • D) Boolean
  • Explanation: All data stored in localStorage is stored as strings.

100.               What will happen if you try to access an index that does not exist in an array?

  • A) It will throw an error
  • B) It will return undefined
  • C) It will return null
  • D) It will return an empty string
  • Explanation: Accessing an index that does not exist in an array will return undefined.

 

Post a Comment

0Comments

Post a Comment (0)