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) --- .../reference/statements/function/index.html | 172 --------------------- 1 file changed, 172 deletions(-) delete mode 100644 files/ca/web/javascript/reference/statements/function/index.html (limited to 'files/ca/web/javascript/reference/statements/function') diff --git a/files/ca/web/javascript/reference/statements/function/index.html b/files/ca/web/javascript/reference/statements/function/index.html deleted file mode 100644 index 207c3b0af8..0000000000 --- a/files/ca/web/javascript/reference/statements/function/index.html +++ /dev/null @@ -1,172 +0,0 @@ ---- -title: function -slug: Web/JavaScript/Reference/Statements/function -translation_of: Web/JavaScript/Reference/Statements/function -original_slug: Web/JavaScript/Referencia/Sentencies/function ---- -
-
{{jsSidebar("Statements")}}
-
- -

Resum

- -

La declaració d'una funció defineix una funció amb uns paràmetres especificats.

- -
-

També podeu definir funcions fent servir el constructor {{jsxref("Function")}} i un {{jsxref("Operators/function", "function expression")}}.

-
- -

Sintaxi

- -
function nom([paràm,[, paràm,[..., paràm]]]) {
-   [sentències]
-}
-
- -
-
nom
-
El nom de la funció.
-
- -
-
paràm
-
El nom d'un argument que se li passarà a la funció. Una funció pot arribar a tenir fins a 255 arguments.
-
- -
-
sentències
-
Les sentències que comprenen el cos de la funció.
-
- -

Descripció

- -

Una funció creada amb una declaració d'una funció és un objecte Function i té totes les propietats, mètodes i comportament dels objectes Function. Vegeu {{jsxref("Function")}} per informació detallada sobre funcions.

- -

Una funció també es pot crear fent servir una expressió (vegeu {{jsxref("Operators/function", "function expression")}}).

- -

Per defecte, les funcions retornen undefined. Per tal de retornar qualsevol altre valor, la funció ha de tenir una sentència {{jsxref("Statements/return", "return")}} que especifiqui el valor que retorna.

- -

Funcions creades de forma condicional

- -

Les funcions poden ser declarades de forma condicional, és a dir, una sentència d'una funció pot estar aniuada dins d'una sentència if. La majoria de navegadors que no siguin Mozilla tractaran aquestes declaracions condicionals com a declaracions incondicionals i crearàn la funció tant si la condició és vertadera o falsa, vegeu aquest article per una visió general. Per tant, no s'haurien de fer servir, per creacions condicionals feu servir expressions de funcions.

- -

Declarar les funcions abans de definir-les (hosting)

- -

Function declarations in JavaScript are hoisting the function definition. En Javascript es pot ser cridar una funció abans de declarar-la. En anglès existeix un ver:

- -
hoisted(); // logs "foo"
-
-function hoisted() {
-  console.log("foo");
-}
-
- -

Vegeu que {{jsxref("Operators/function", "function expressions")}} no estan hoisted:

- -
notHoisted(); // TypeError: notHoisted is not a function
-
-var notHoisted = function() {
-   console.log("bar");
-};
-
- -

Exemples

- -

Exemple: Fer servir function

- -

El codi següent declara una funció que retorna la quantitat total de vendes, quan se li dóna el nombre d'unitat venudes d' a, b, i c.

- -
function calc_sales(units_a, units_b, units_c) {
-   return units_a*79 + units_b * 129 + units_c * 699;
-}
-
- -

Especificacions

- - - - - - - - - - - - - - - - - - - - - - - - -
EspecificacióEstatComentaris
1a edició de ECMAScript.EstàndardDefinició iniciañ. Implementat en JavaScript 1.0
{{SpecName('ES5.1', '#sec-13', 'Function definition')}}{{Spec2('ES5.1')}} 
{{SpecName('ES6', '#sec-function-definitions', 'Function definitions')}}{{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