I don't understand this if else conditon syntax

This is the funciton i dont undestant. We know that there is if and else in a if-else block. But here is no “else”. Also there is nothing writtern after “return”. What does this code mean?

function myFunction(){
  let target = event.target;
  if (target.tagName != 'TD') return; 

Instead of using ‘if, else’ you can accomplish something similar using ‘if, return’ instead. After you return from the function, the rest of the code below that won’t be executed. You don’t need else if the code below the if will never run anyways.

Not sure if the one-liner if confuses you, but you dont need the braces ‘{}’ if your if statement is just a one liner, you can omit them in that case.

1 Like