“Switch JS” Respostas de código

Switch JS

switch(expression) {
  case x:
    // code block
    break;
  case y:
    // code block
    break;
  default:
    // code block
}
Grotesque Grebe

Declaração de Javascript Declaração vários casos

//javascript multiple case switch statement
var color = "yellow";
var darkOrLight="";
switch(color) {
    case "yellow":case "pink":case "orange":
        darkOrLight = "Light";
        break;
    case "blue":case "purple":case "brown":
        darkOrLight = "Dark";
        break;
    default:
        darkOrLight = "Unknown";
}

//darkOrLight="Light"
Grepper

Javascript Switch Case Code Format

switch(type) {
	case "SomeString":
		// Functionality
		break;
	case "OtherString":
		// Functionality
		break;
	default:
		// Functionality
		break;
}
Nathan uses Linux

Switch JS

switch (expr) {
  case 'Oranges':
    console.log('Oranges are $0.59 a pound.');
    break;
  case 'Apples':
    console.log('Apples are $0.32 a pound.');
    break;
  case 'Bananas':
    console.log('Bananas are $0.48 a pound.');
    break;
  case 'Cherries':
    console.log('Cherries are $3.00 a pound.');
    break;
  case 'Mangoes':
  case 'Papayas':
    console.log('Mangoes and papayas are $2.79 a pound.');
    break;
  default:
    console.log('Sorry, we are out of ' + expr + '.');
}

console.log("Is there anything else you'd like?");
Yucky Yak

Switch JS

switch (expression) {
  case valeur1:
    // Instructions à exécuter lorsque le résultat
    // de l'expression correspond à valeur1
    instructions1;
    [break;]
  case valeur2:
    // Instructions à exécuter lorsque le résultat
    // de l'expression correspond à valeur2
    instructions 2;
    [break;]
  ...
  case valeurN:
    // Instructions à exécuter lorsque le résultat
    // de l'expression à valeurN
    instructionsN;
    [break;]
  [default:
    // Instructions à exécuter lorsqu'aucune des valeurs
    // ne correspond
    instructions_def;
    [break;]]
}
Friendly Falcon

Switch JS

switch(expression) {
  case x:
    // code block
    break;
  default:
    // code block
}
Fantastic Flamingo

Respostas semelhantes a “Switch JS”

Perguntas semelhantes a “Switch JS”

Mais respostas relacionadas para “Switch JS” em JavaScript

Procure respostas de código populares por idioma

Procurar outros idiomas de código