Looks like no one added any tags here yet for you.
Q: What is a conditional statement?
A: A rule or idea that can be expressed using the word "if"; often used to express business rules in programming.
Q: Give an example of a business rule using a conditional statement.
A: If a suitcase weighs over 50 pounds, charge an extra $20.
Q: What is client-side error trapping?
A: Checking user input in the browser before sending data to a server to provide a better user experience.
Q: How do you write a simple "if" statement in JavaScript?
if (condition) { // code to execute if condition is true
Q: What are Boolean values?
A: true
and false
values that determine the outcome of conditions.
Q: What is the difference between =
and ==
in JavaScript?
A: =
is for assignment, while ==
is for comparison.
Q: What are comparison operators in JavaScript?
A: ==
, !=
, <
, >
, <=
, >=
Q: How do you write an if-else
statement in JavaScript?
if (age < 18) {
console.log("Not old enough to vote.");
} else {
console.log("Old enough to vote.");
{
Q: How does an if-else if-else
chain work?
A: It allows checking multiple conditions, executing only the first block that evaluates to true
.
Q: What does the isNaN()
function do?
A: It checks if a value is not a number, returning true
for non-numeric values.
Q: Does isNaN("")
return true
or false
?
A: false
, because JavaScript treats an empty string as zero.
Q: What is a zero-length string, and how is it different from a space-filled string?
A: ""
has length 0, whereas " "
has length 1 due to the space character.
Q: Why should you avoid using prompt()
and alert()
in modern web development?
A: They cause accessibility issues and make the browser "hang" while waiting for user action.
Q: What is a good practice for writing conditional statements?
A: Start with a simple if
statement before adding else
or else if
.