My love for if/else statements in JavaScript

Kate Rigney
2 min readMar 19, 2018

--

Not going to lie — JavaScript is trying to break my brain. I know that it’s good to do once in awhile and that’s how you learn…but seriously. After how easily HTML and CSS came to me, I got a little hit upside the head with JavaScript this week. In the middle of all the confusion, repeated questions, and syntax error there is one thing to which I know I can relate: if/else statements!

I am a person who loves clear definitions and accounting for multiple outcomes. My creative brain comes up with all sorts of scenarios for any situation. It’s so great for my anxiety.

I’m self-diagnosing that this is why I if/else statements in JavaScript make so much sense to me. You can clearly define a condition and if it proves true you can create an outcome that is carried out. AND you can set it up so that multiple conditions/different outcomes are accounted for! So cool. (Yes, I am a nerd).

Basic structure is this:

if (condition that is being evaluated true or false){ code that defines the outcome to carry out if condition is true }

— — If the first condition proves false then the next statement will be evaluated and so on.

else if (condition that is being evaluated true or false){ code that defines the outcome to carry out if condition is true }

else { code that defines the outcome to carry out if none of the other conditions are true }

In the work we’ve already done, I can so see so many uses for these. IF/ELSE STATEMENTS ALL THE TIME! Just look at my code here:

Seriously though, it is very nice to find something in JavaScript I feel like I get fully. I’m looking forward to feeling more comfortable as I move forward as a new developer.

--

--