JavaScript (Control Structures- Conditional) Flashcards

(12 cards)

1
Q

are the building blocks of logic in
JavaScript. They allow programs to make decisions and
repeat actions based on conditions

A

Control structures

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Control Structures
(Categories)

A
  • Conditional (Decision-Making) Structures
  • Loops
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

allow a program to evaluate a
condition (a Boolean expression) and execute specific blocks
of code based on whether the condition is true or false.

A

Conditional structures

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q
  • condition is a Boolean expression (evaluates to true or
    false).
  • executes code only if a condition is true.
  • If the condition is true, the code block inside the {}
    runs.
  • If the condition is false, the code block is skipped
A

if statement

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q
  • Adds an alternative path when the condition is false.
  • The if part checks a condition.
  • If the condition is true, the code inside the if block runs.
  • If the condition is false, the code inside the else block
    runs instead.
A

If…else statemen

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q
  • JavaScript checks the conditions from top to bottom.
  • As soon as it finds a condition that is true, it executes
    that block and skips the rest.
  • If no condition is true, the code inside the else block (if
    provided) runs.
A

if…else if…else

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

is another control flow
structure, similar to if…else if…else, but it’s often cleaner
and easier to read when you’re checking a single variable or
expression against multiple possible values.
* Used when you’re comparing one value against many cases.
* A cleaner way to handle multiple specific values of a single
variable

A

switch Statement

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

play a critical role
in
how expressions are evaluated in control flow
structures like if statements, loops, and ternary
operators. Understanding this concept is key to writing
efficient and bug-free code.

A

truthy and falsy values

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

is a value that, when coerced to a boolean,
results in false.

A

falsy value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

is any value that is not falsy. In other
words, if a value is not one of the falsy values (listed
above), it is considered truthy.

A

truthy value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

falsy value example

A
  1. false — the boolean value false.
  2. 0 — the number zero.
    3.-0 — the negative zero (still falsy).
  3. ”” (empty string) — an empty string is considered falsy.
  4. null — represents the absence of a value.
  5. undefined — represents an uninitialized or missing value.
  6. NaN — represents “Not-a-Number,” the result of an invalid
    mathematical operation.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

truthy value

A
  1. true — the boolean value true.
  2. Any non-zero number — e.g., 1, -1, 42, etc.
  3. Non-empty string — e.g., “hello”, “false”, “0”, “ “ (a
    string with a space).
  4. [] (empty array) — an empty array is truthy.
  5. {} (empty object) — an empty object is truthy.
  6. function() — any function is truthy.
  7. Infinity and -Infinity — both are truthy.
  8. new Date() — any valid Date object is truthy
How well did you know this?
1
Not at all
2
3
4
5
Perfectly