Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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
Comment

JavaScript Switch Statement

 switch (new Date().getDay()) {
  case 0:
    day = "Sunday";
    break;
  case 1:
    day = "Monday";
    break;
  case 2:
     day = "Tuesday";
    break;
  case 3:
    day = "Wednesday";
    break;
  case 4:
    day = "Thursday";
    break;
  case 5:
    day = "Friday";
    break;
  case 6:
    day = "Saturday";
}     

console.log(day);
Comment

Javascript Switch Syntax

switch(condition){
    case 'value1' :
        //code
        [break;]
    case 'value2' :
        //code
        [break;]
    .......
    default :
        //code
        [break;]
}
Comment

javascript switch statement

switch (new Date().getDay()) {      // input is current day
case 6:                         // if (day == 6)
	text = "Saturday";          
	break;
case 0:                         // if (day == 0)
	text = "Sunday";
	break;
default:                        // else...
	text = "Whatever";
}
Comment

JavaScript Switch Statement

switch(variable/expression) {
    case value1:  
        // body of case 1
        break;

    case value2:  
        // body of case 2
        break;

    case valueN:
        // body of case N
        break;

    default:
        // body of default
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript push dictionary into array 
Javascript :: status 502 bad api gateway error solution for aws lambda 
Javascript :: javascript check if object is null or empty 
Javascript :: swap function javascript 
Javascript :: new Date() get speicifc hours min sec 
Javascript :: how to add json file to mongodb 
Javascript :: regex to check 8 < length < 16, one uppercase, one lowercase and must have at least one number and one special character 
Javascript :: node js connect to mongodb using mongoose 
Javascript :: enable button 
Javascript :: multithreading in javascript 
Javascript :: how to check if the first letter of a string is capitalized or uppercase in js 
Javascript :: javascript prompt yes/no 
Javascript :: materialize open modal on load 
Javascript :: string number to array 
Javascript :: antd react native 
Javascript :: copy paste menu react native textinput disable 
Javascript :: base href 
Javascript :: Javascript Show HTML Elements 
Javascript :: join 2 array in javascript 
Javascript :: how to convert string to camel case in javascript 
Javascript :: beautify console log result 
Javascript :: footer react 
Javascript :: window.location.href url.action parameters 
Javascript :: track scroll javascript 
Javascript :: react router base url 
Javascript :: react electron boilerplate 
Javascript :: create loop to specific length react 
Javascript :: how to counts date from moment js 
Javascript :: fullcalendar angular add events 
Javascript :: es6 features javascript 
ADD CONTENT
Topic
Content
Source link
Name
5+8 =