Conditional Rendering in React Complete Guide with Examples 2026

Image
  Conditional Rendering in React Conditional Rendering is one of the most useful concepts in React. It means showing different content on the screen depending on a condition. For example: If a user is logged in → show Logout If a user is not logged in → show Login If a student has passed → show Congratulations If a product is available → show Buy Now If data is loading → show Loading... React does not have a separate if rendering tag. Instead, we use normal JavaScript conditions such as if, the ternary operator, &&, and switch to decide what should appear in the UI.

Top 25 HTML MCQ With Answers(part 5)


Top 25 HTML  MCQ With Answers



Top 25 HTML  MCQ With Answers


1] Which of the following is client-side scripting language

a) JavaScript

b)PHP

c) HTML

d) Java

Answer: a) JavaScript


2] Which tag is use to include JavaScript in an HTML file?

a) <java>
b) <javascript>
c) <script>
d) <scripting>

Answer: c) <script>

3] JavaScript is a _______ language.

a) Server-side-language
b) Client-side
c) Compiled
d) Assembly

Answer: b) Client-side

4] What is the correct syntax for external JavaScript file?

a) <script src="script.js">

b) <script href="script.js">

c) <script ref="script.js">

d) <script link="script.js">

Answer: a) <script src="script.js">


5] Which function is used to display an alert box in JavaScript language?

a) alertBox()
b) msgBox()
c) alert()
d) display()

Answer: c) alert()


6] Which keyword is define a JavaScript variable?

a) var

b) let

c) const

d) All of the above

Answer: d) All of the above


7]What will type of ([]) return in JavaScript language?

a) object
b) array
c) list
d) undefined

Answer: a) object


8] What is the correct way to write a comment in JavaScript language ?

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


9] Which of the following is NOT a JavaScript framework?

a) React
b) Angular
c) Django
d) Vue

Answer: c) Django


10] Which event is triggered when a user clicks an HTML element?

a) onmouseover
b) onclick
c) onload
d) onsubmit

Answer: b) onclick


11] How do you call a function named myFunction in JavaScript language?

a) call myFunction();
b) myFunction();
c) call function myFunction();
d) execute myFunction();

Answer: b) myFunction();


12] Which of the following is use to loop through an array in JavaScript language?

a) for
b) while
c) forEach
d) All of the above

Answer: d) All of the above


13] What is the purpose of the return statement in JavaScript language?

a) Stops function execution
b) Returns a value from a function
c) Both a and b
d) None of the above

Answer: c) Both a and b


14] What will console.log(2 + "2") output?

a) 14
b) "22"
c) 28
d) Error

Answer: b) "22"

15] How do you declare a function in JavaScript language?

a) function myFunction() {}

b) def myFunction() {}

c) function: myFunction() {}

d) func myFunction() {}

Answer: a) function myFunction() {}


16] Which method converts a string to uppercase in JavaScript language?

a) upperCase()
b) toUpperCase()
c) makeUpperCase()
d) convertUpperCase()

Answer: b) toUpperCase()


17] What  output of console.log(typeof null)?

a) null
b) object
c) undefined
d) string

Answer: b) object


18] How do you write an IF statement in JavaScript language?

a) if (x == 5) {}
b) if x == 5 then {}
c) if x = 5 {}
d) if x == 5 {}

Answer: a) if (x == 5) {}


19] What is the output of console.log(3 == "3")?

a) true
b) undefined
c) Error
d) defined

Answer: a) true


20] What does NaN stand for in JavaScript?

a) Not a Name
b) Not a Number
c) Null and None
d) New and Next

Answer: b) Not a Number


21] How do you access an HTML element with the ID demo using JavaScript language?

a) document.getElementById("demo")
b) document.querySelector("#demo")
c) Both a and b
d) None of the above

Answer: c) Both a and b


22] Which function is used to add an event listener in JavaScript language?

a) addEventListener()

b) attachEvent()

c) onEvent()

d) setEventListener()

Answer: a) addEventListener()


23] Which property is used to change the HTML content using JavaScript language?

a) innerHTML

b) textContent

c) Both a and b

d) None of the above

Answer: c) Both a and b


24] How do you remove an HTML element using JavaScript language?

a) removeElement()

b) deleteElement()

c) removeChild()

d) removeNode()

Answer: c) removeChild()


25] Which method stops event propagation?

a) stopPropagation()
b) preventDefault()
c) cancelBubble()
d) stopEvent()

Answer: a) stopPropagation()

Related Post 

html login in form

Comments

Popular posts from this blog

HTML Tag

CSS Text Color Explained with Syntax and HTML Examples

HTML Input Type Submit Syntax and Example