From 95aca4b4d8fa62815d4bd412fff1a364f842814a Mon Sep 17 00:00:00 2001 From: Ryan Johnson Date: Thu, 29 Apr 2021 16:16:42 -0700 Subject: remove retired locales (#699) --- .../operators/conditional_operator/index.html | 171 --------------------- 1 file changed, 171 deletions(-) delete mode 100644 files/ca/web/javascript/reference/operators/conditional_operator/index.html (limited to 'files/ca/web/javascript/reference/operators/conditional_operator') diff --git a/files/ca/web/javascript/reference/operators/conditional_operator/index.html b/files/ca/web/javascript/reference/operators/conditional_operator/index.html deleted file mode 100644 index 0cfbd791a3..0000000000 --- a/files/ca/web/javascript/reference/operators/conditional_operator/index.html +++ /dev/null @@ -1,171 +0,0 @@ ---- -title: Operador Condicional (ternari) -slug: Web/JavaScript/Reference/Operators/Conditional_Operator -translation_of: Web/JavaScript/Reference/Operators/Conditional_Operator -original_slug: Web/JavaScript/Referencia/Operadors/Conditional_Operator ---- -
-
{{jsSidebar("Operators")}}
-
- -

Resum

- -

L'operador condicional (ternari) és l'únic operador de JavaScript que opera amb tres operands. Aquest operador és freqüentment usat com una simplificació de la sentència if.

- -

Sintaxi

- -
condition ? expr1 : expr2 
- -

Paràmetres

- -
-
condition
-
Una expressió que avalua true o false.
-
- -
-
expr1, expr2
-
Expressions amb valors de qualsevol tipus.
-
- -

Descripció

- -

Si condition és true, l'operador retorna el valor de expr1; de ser el contrari, retorna el valor de expr2. Per exemple, per mostrar diferents missatges basats en el valor de la variable isMember, es podria fer servir aquesta sentència:

- -
"The fee is " + (isMember ? "$2.00" : "$10.00")
-
- -

També es pot assignar variables depenent del resultat ternari:

- -
var elvisLives = Math.PI > 4 ? "Yep" : "Nope";
- -

És possible realitzar avaluacions ternàries múltiples (nota: L'operador condicional operator s'associa per la dreta):

- -
var firstCheck = false,
-    secondCheck = false,
-    access = firstCheck ? "Access denied" : secondCheck ? "Access denied" : "Access granted";
-
-console.log( access ); // logs "Access granted"
- -

També es pot usar avaluacions ternàries en espais lliures per tal de fer diferents operacions:

- -
var stop = false, age = 16;
-
-age > 18 ? location.assign("continue.html") : stop = true;
-
- -

També es pot fer més d'una sola operació per cas, separant-les amb una coma:

- -
var stop = false, age = 23;
-
-age > 18 ? (
-    alert("OK, you can go."),
-    location.assign("continue.html")
-) : (
-    stop = true,
-    alert("Sorry, you are much too young!")
-);
-
- -

I per últim, també es pot fer més d'una operació durant l'assignació d'un valor. En aquest cas, el últim valor del parèntesis serparat per una coma serà el valor assignat.

- -
var age = 16;
-
-var url = age > 18 ? (
-    alert("OK, you can go."),
-    // alert returns "undefined", but it will be ignored because
-    // isn't the last comma-separated value of the parenthesis
-    "continue.html" // the value to be assigned if age > 18
-) : (
-    alert("You are much too young!"),
-    alert("Sorry :-("),
-    // etc. etc.
-    "stop.html" // the value to be assigned if !(age > 18)
-);
-
-location.assign(url); // "stop.html"
- -

Especificacions

- - - - - - - - - - - - - - - - - - - - - - - - -
EspecificacióEstatComentaris
1a edició deECMAScript.EstàndardDefinició inicial. Implementat en JavaScript 1.0
{{SpecName('ES5.1', '#sec-11.12', 'The conditional operator')}}{{Spec2('ES5.1')}} 
{{SpecName('ES6', '#sec-conditional-operator', 'Conditional Operator')}}{{Spec2('ES6')}} 
- -

Compatibilitat amb navegadors

- -

{{CompatibilityTable}}

- -
- - - - - - - - - - - - - - - - - - - -
CaracterísticaChromeFirefox (Gecko)Internet ExplorerOperaSafari
Suport bàsic{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
-
- -
- - - - - - - - - - - - - - - - - - - - - -
CaracterísticaAndroidChrome per AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Suport bàsic{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
-
- -

Vegeu també

- - -- cgit v1.2.3-54-g00ecf