I certainly care about if/else statements, and so do those who code! The if and else statements allow you to run a code conditionally based on whether something is true or false. This is considered a type of Boolean expression. Basically, you can code any expression to determine whether the data is true or false. Essentially you are saying if the data is true do x,y,z, or else do a,b,c. Personally, when I take a second to think about it, the if and else make sense in what you are trying to do. In class, we related the if/else statements to a swimlane type of flow chart and that really did help me understand. If you think of an if/else statement as a diamond, then it is a decision that must be made. With that being said, Javascript is making the decision as to whether or not the data is true or false. Then, that decision then leads to what the output of the code will be. So, if/else statements are yet another important aspect of Javascript that is useful to understand and utilize in codes!
Image link: https://medium.com/swlh/5-ways-to-replace-if-else-statements-857c0ff19357
Leave a Reply
You must be logged in to post a comment.