javascript switch statement fallthrough code example

Example 1: switch case mdn

switch (expression) {
  case value1:
    //Statements executed when the
    //result of expression matches value1
    [break;]
  case value2:
    //Statements executed when the
    //result of expression matches value2
    [break;]
  ...
  case valueN:
    //Statements executed when the
    //result of expression matches valueN
    [break;]
  [default:
    //Statements executed when none of
    //the values match the value of the expression
    [break;]]
}

Example 2: javascript switch assignment

var price = (function(color) {
  switch(color) {
    case 'red':
      return 10;
    case 'blue':
      return 20;
    default:
      return 30;
  }
})('blue');

console.log(price); // Will print 20