Conditional Statements

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/13

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

14 Terms

1
New cards

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.

2
New cards

Q: Give an example of a business rule using a conditional statement.

A: If a suitcase weighs over 50 pounds, charge an extra $20.

3
New cards

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.

4
New cards

Q: How do you write a simple "if" statement in JavaScript?

if (condition) { // code to execute if condition is true

5
New cards

Q: What are Boolean values?

A: true and false values that determine the outcome of conditions.

6
New cards

Q: What is the difference between = and == in JavaScript?

A: = is for assignment, while == is for comparison.

7
New cards

Q: What are comparison operators in JavaScript?

A: ==, !=, <, >, <=, >=

8
New cards

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.");

{

9
New cards

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.

10
New cards

Q: What does the isNaN() function do?

A: It checks if a value is not a number, returning true for non-numeric values.

11
New cards

Q: Does isNaN("") return true or false?

A: false, because JavaScript treats an empty string as zero.

12
New cards

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.

13
New cards

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.

14
New cards

Q: What is a good practice for writing conditional statements?

A: Start with a simple if statement before adding else or else if.