Skip to content

Latest commit

 

History

History
530 lines (407 loc) · 14.6 KB

js_mcqs.md

File metadata and controls

530 lines (407 loc) · 14.6 KB

Basic HTML Structure (6 MCQs)

  1. What is the correct HTML document structure?

    • a) <!DOCTYPE html><html><head></head><body></body></html>
    • b) <html><head><body></body></head></html>
    • c) <!DOCTYPE html><body><head></head></body></html>
    • d) <html><body><head></head></body></html>
    • Answer: a) <!DOCTYPE html><html><head></head><body></body></html>
  2. Which tag is used to create a paragraph in HTML?

    • a) <p>
    • b) <div>
    • c) <span>
    • d) <h1>
    • Answer: a) <p>
  3. Which tag represents the main content of a document in HTML5?

    • a) <section>
    • b) <main>
    • c) <header>
    • d) <article>
    • Answer: b) <main>
  4. What is the purpose of the href attribute in an <a> tag?

    • a) To specify the link's appearance
    • b) To define the hyperlink's URL
    • c) To change the text style
    • d) To embed an image
    • Answer: b) To define the hyperlink's URL
  5. Which tag is used for unordered lists?

    • a) <ol>
    • b) <ul>
    • c) <li>
    • d) <table>
    • Answer: b) <ul>
  6. Which element defines a header for a section or page?

    • a) <footer>
    • b) <header>
    • c) <article>
    • d) <nav>
    • Answer: b) <header>

Links, Lists, and Tables (4 MCQs)

  1. What tag is used to create an ordered list?

    • a) <ul>
    • b) <ol>
    • c) <li>
    • d) <dl>
    • Answer: b) <ol>
  2. How do you create a table header in HTML?

    • a) <td>
    • b) <th>
    • c) <thead>
    • d) <tr>
    • Answer: b) <th>
  3. What attribute is used to specify the URL of a hyperlink?

    • a) src
    • b) href
    • c) link
    • d) target
    • Answer: b) href
  4. Which tag is used to define a table row?

    • a) <td>
    • b) <tr>
    • c) <th>
    • d) <table>
    • Answer: b) <tr>

Media Elements (3 MCQs)

  1. Which tag is used to embed an image in HTML?

    • a) <img>
    • b) <media>
    • c) <video>
    • d) <source>
    • Answer: a) <img>
  2. Which attribute is required in the <img> tag to define the source of the image?

    • a) href
    • b) src
    • c) alt
    • d) link
    • Answer: b) src
  3. Which attribute makes an audio or video file start playing automatically?

    • a) loop
    • b) autoplay
    • c) controls
    • d) src
    • Answer: b) autoplay

HTML5 APIs and Features (3 MCQs)

  1. Which API is used to get the geographical location of a user?

    • a) Web Storage API
    • b) Canvas API
    • c) Geolocation API
    • d) WebSocket API
    • Answer: c) Geolocation API
  2. What does localStorage allow in HTML5?

    • a) Storing data permanently in the browser
    • b) Storing session data
    • c) Storing cookies
    • d) Storing server-side data
    • Answer: a) Storing data permanently in the browser
  3. Which HTML5 element is used for 2D graphics?

    • a) <img>
    • b) <canvas>
    • c) <svg>
    • d) <video>
    • Answer: b) <canvas>

Forms & Input Elements (4 MCQs)

  1. Which tag is used to create a form in HTML?

    • a) <form>
    • b) <input>
    • c) <textarea>
    • d) <select>
    • Answer: a) <form>
  2. Which attribute is used to specify the action URL in a form?

    • a) method
    • b) action
    • c) src
    • d) target
    • Answer: b) action
  3. Which input type is used for a multi-line text input?

    • a) text
    • b) textarea
    • c) password
    • d) button
    • Answer: b) textarea
  4. Which attribute is used to group related options in a dropdown list?

    • a) group
    • b) fieldset
    • c) optgroup
    • d) select
    • Answer: c) optgroup

Basic CSS Syntax and Selectors (6 MCQs)

  1. Which symbol is used to select an ID in CSS?

    • a) .
    • b) #
    • c) >
    • d) *
    • Answer: b) #
  2. What does the following CSS selector p select?

    • a) All elements with the class p
    • b) All <p> tags
    • c) All elements with the ID p
    • d) All paragraph elements inside a <div>
    • Answer: b) All <p> tags
  3. Which of the following is a CSS class selector?

    • a) #header
    • b) .container
    • c) h1
    • d) div > p
    • Answer: b) .container
  4. How do you select all paragraph tags inside a div tag?

    • a) div p
    • b) div > p
    • c) p div
    • d) p, div
    • Answer: a) div p
  5. What is the correct syntax to apply a background color in CSS?

    • a) background-color: blue;
    • b) color-background: blue;
    • c) bg-color: blue;
    • d) color: blue;
    • Answer: a) background-color: blue;
  6. Which selector is used to style the hover state of a link in CSS?

    • a) :hover
    • b) :focus
    • c) :active
    • d) :visited
    • Answer: a) :hover

Styling Texts and Fonts (3 MCQs)

  1. Which CSS property changes the text color?

    • a) font-color
    • b) text-color
    • c) color
    • d) background-color
    • Answer: c) color
  2. What is the correct CSS syntax to change the font size?

    • a) font: size 20px;
    • b) font-size: 20px;
    • c) text-size: 20px;
    • d) font: 20px;
    • Answer: b) font-size: 20px;
  3. Which property changes the font family of text in CSS?

    • a) font-type
    • b) text-family
    • c) font-family
    • d) typeface
    • Answer: c) font-family

Responsive Design and Media Queries (2 MCQs)

  1. What is the correct syntax for a media query in CSS?

    • a) @screen and (max-width: 768px)
    • b) @media screen and (max-width: 768px)
    • c) @media-query screen (768px)
    • d) media (max-width: 768px)
    • Answer: b) @media screen and (max-width: 768px)
  2. What is the mobile-first approach in responsive design?

    • a) Designing for desktop first, then adjusting for mobile
    • b) Designing for mobile devices first, then enhancing for larger screens
    • c) Ignoring mobile devices and focusing on desktop
    • d) Designing for tablets first
    • Answer: b) Designing for mobile devices first, then enhancing for larger screens

Flexbox and Grid Layout (4 MCQs)

  1. Which CSS property defines a flex container?

    • a) display: flex;
    • b) flex-direction: row;
    • c) grid-template-columns
    • d) align-items: center;
    • Answer: a) display: flex;
  2. What does the justify-content property in flexbox control?

    • a) Spacing between flex items
    • b) Alignment of items along the cross axis
    • c) Width of flex items
    • d) Alignment of items along the main axis
    • Answer: d) Alignment of items along the main axis
  3. How do you define a grid container in CSS?

    • a) display: grid;
    • b) grid: flex;
    • c) grid-template: row;
    • d) align-items: grid;
    • Answer: a) display: grid;
  4. What does the grid-template-rows property define?

    • a) Height of grid items
    • b) Number of rows in the grid
    • c) Spacing between grid items
    • d) Width of grid columns
    • Answer: b) Number of rows in the grid

More HTML, CSS

HTML MCQs:

11) Which tag is used to create an unordered list?

  • Answer: a) <ul>

12) Which attribute of the <a> tag specifies the URL of the page the link goes to?

  • Answer: a) href

13) How do you create a table row in HTML?

  • Answer: b) <tr>

14) Which tag is used to define a table header?

  • Answer: a) <th>

20) Which of the following allows you to store data on the client side?

  • Answer: d) Local Storage

CSS MCQs:

21) Which of the following is the correct syntax for applying a style to an HTML element?

  • Answer: a) selector {property: value;}

22) Which selector is used to select elements with a specific class?

  • Answer: c) .

23) How do you select an element with the ID "header"?

  • Answer: b) #header { }

24) Which selector is used to select all elements on a page?

  • Answer: a) *

25) Which CSS property is used to change the text color of an element?

  • Answer: b) color

26) What does the following CSS selector select: div > p?

  • Answer: b) All <p> elements inside <div> elements

27) Which of the following properties is NOT part of the CSS box model?

  • Answer: d) outline

28) Which property is used to change the background color of an element?

  • Answer: b) background-color

29) What value of the display property makes an element disappear from the page layout?

  • Answer: b) none

30) Which CSS property controls the stacking order of elements?

  • Answer: a) z-index

31) Which position value allows an element to be positioned relative to its normal position?

  • Answer: b) relative

32) Which property is used to align items along the main axis in Flexbox?

  • Answer: b) justify-content

33) Which of the following properties defines the columns of a grid container?

  • Answer: a) grid-template-columns

34) What is the default value of the flex-direction property?

  • Answer: a) row

35) Which property is used to create a responsive layout in CSS Grid?

  • Answer: c) grid-template-columns

36) Which property is used to change the font of an element?

  • Answer: a) font-family

37) How do you include Google Fonts in a CSS file?

  • Answer: d) a and b

38) Which property is used to add shadow to text?

  • Answer: a) text-shadow

39) Which of the following is a correct media query?

  • Answer: d) All of the above

40) Which term describes designing websites to look good on all devices?

  • Answer: a) Responsive Design

Basic JavaScript Syntax and Data Types (6 MCQs)

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

    • a) var
    • b) const
    • c) let
    • d) All of the above
    • Answer: d) All of the above
  2. Which of the following is not a data type in JavaScript?

    • a) string
    • b) number
    • c) boolean
    • d) float
    • Answer: d) float
  3. Which operator is used to compare both value and type in JavaScript?

    • a) ==
    • b) ===
    • c) !=
    • d) !==
    • Answer: b) ===
  4. How do you create an array in JavaScript?

    • a) let arr = {};
    • b) let arr = [];
    • c) let arr = array();
    • d) let arr = ();
    • Answer: b) let arr = [];
  5. Which of the following is a correct way to write a function in JavaScript?

    • a) function myFunction() { return true; }
    • b) def myFunction() { return true; }
    • c) myFunction() => { return true; }
    • d) fn myFunction() { return true; }
    • Answer: a) function myFunction() { return true; }
  6. How do you add a comment in JavaScript?

    • a) # This is a comment
    • b) // This is a comment
    • c) /* This is a comment */
    • d) Both b and c
    • Answer: d) Both b and c

JavaScript Events and Forms (3 MCQs)

  1. Which event occurs when a user clicks on an HTML element?

    • a) onchange
    • b) onclick
    • c) onmouseover
    • d) onkeydown
    • Answer: b) onclick
  2. Which method is used to access the value of an input field in JavaScript?

    • a) getElementById().value
    • b) getElementsByTagName().value
    • c) querySelector().content
    • d) getAttribute().value
    • Answer: a) getElementById().value
  3. How do you prevent the default action of an event in JavaScript?

    • a) event.preventDefault()
    • b) event.returnValue = false
    • c) stopPropagation()
    • d) event.stop()
    • Answer: a) event.preventDefault()

DOM Manipulation (4 MCQs)

  1. Which method is used to select an element by its ID?

    • a) document.querySelector()
    • b) document.getElementById()
    • c) document.getElementsByTagName()
    • d) document.getElementsByClassName()
    • Answer: b) document.getElementById()
  2. How do you change the inner HTML content of an element?

    • a) element.innerText = "new content";
    • b) element.value = "new content";
    • c) element.innerHTML = "new content";
    • d) element.content = "new content";
    • Answer: c) element.innerHTML = "new content";
  3. Which JavaScript property is used to modify the CSS style of an element?

    • a) style
    • b) css
    • c) attribute
    • d) class
    • Answer: a) style
  4. How do you add an event listener to an element in JavaScript?

    • a) element.onClick = function(){}
    • b) element.addEventListener("click", function(){})
    • c) element.click(function(){})
    • d) element.listen("click", function(){})
    • Answer: b) `element

.addEventListener("click", function(){})`

More JS

41) How do you declare a JavaScript variable?

  • Answer: d) All of the above

42) Which of the following is NOT a JavaScript data type?

  • Answer: d) character

43) What is the result of 2 + "2" in JavaScript?

  • Answer: b) 22

44) Which operator is used to assign a value to a variable?

  • Answer: b) =

45) What is the correct way to write a JavaScript array?

  • Answer: a) var colors = ["red", "green", "blue"];

46) Which of the following is the strict equality operator in JavaScript?

  • Answer: b) ===

47) Which statement is used to stop a loop in JavaScript?

  • Answer: a) break

48) What will the following code output:

if (false) { console.log("True"); }  
else { console.log("False"); }  
  • Answer: b) False

49) How do you write a JavaScript switch statement?

  • Answer: b) switch(x) {case "a": break;}

50) Which of the following is the correct way to define a function in JavaScript?

  • Answer: d) All of the above

51) Which of the following is the correct way to define a function in JavaScript?

  • Answer: d) a and b

52) Which property is used to change the content of an HTML element?

  • Answer: d) All of the above

53) How do you add an event listener in JavaScript?

  • Answer: d) a and b

54) What is the correct syntax for referring to an external script called "script.js"?

  • Answer: c) <script src="script.js">

55) Which event occurs when the user clicks on an HTML element?

  • Answer: c) onclick

56) How do you prevent a form from being submitted in JavaScript?

  • Answer: a) event.preventDefault()

57) Which JavaScript method can be used to validate form input?

  • Answer: b) checkValidity()

58) Which keyword is used to define a constant in ES6?

  • Answer: a) const

59) Which method is used to handle a successful promise resolution?

  • Answer: a) then()

60) Which of the following is the correct JSON format?

  • Answer: a) {"name": "John", "age": 30}