aboutsummaryrefslogtreecommitdiff
path: root/files/pt-pt/web/javascript/reference/extratos_e_declarações
diff options
context:
space:
mode:
authorPeter Bengtsson <mail@peterbe.com>2020-12-08 14:42:52 -0500
committerPeter Bengtsson <mail@peterbe.com>2020-12-08 14:42:52 -0500
commit074785cea106179cb3305637055ab0a009ca74f2 (patch)
treee6ae371cccd642aa2b67f39752a2cdf1fd4eb040 /files/pt-pt/web/javascript/reference/extratos_e_declarações
parentda78a9e329e272dedb2400b79a3bdeebff387d47 (diff)
downloadtranslated-content-074785cea106179cb3305637055ab0a009ca74f2.tar.gz
translated-content-074785cea106179cb3305637055ab0a009ca74f2.tar.bz2
translated-content-074785cea106179cb3305637055ab0a009ca74f2.zip
initial commit
Diffstat (limited to 'files/pt-pt/web/javascript/reference/extratos_e_declarações')
-rw-r--r--files/pt-pt/web/javascript/reference/extratos_e_declarações/bloco/index.html116
-rw-r--r--files/pt-pt/web/javascript/reference/extratos_e_declarações/for/index.html145
-rw-r--r--files/pt-pt/web/javascript/reference/extratos_e_declarações/index.html150
-rw-r--r--files/pt-pt/web/javascript/reference/extratos_e_declarações/return/index.html148
-rw-r--r--files/pt-pt/web/javascript/reference/extratos_e_declarações/throw/index.html271
5 files changed, 830 insertions, 0 deletions
diff --git a/files/pt-pt/web/javascript/reference/extratos_e_declarações/bloco/index.html b/files/pt-pt/web/javascript/reference/extratos_e_declarações/bloco/index.html
new file mode 100644
index 0000000000..a3104dbeae
--- /dev/null
+++ b/files/pt-pt/web/javascript/reference/extratos_e_declarações/bloco/index.html
@@ -0,0 +1,116 @@
+---
+title: Bloco (block)
+slug: Web/JavaScript/Reference/Extratos_e_declarações/bloco
+tags:
+ - Declaração
+ - Funcionalidade de Linguagem
+ - JavaScript
+ - Referencia
+translation_of: Web/JavaScript/Reference/Statements/block
+---
+<div>Bloco {{jsSidebar("Statements")}}</div>
+
+<p>Uma <strong>declaralção bloco </strong>(ou <strong>declaração composto</strong> em outras linguagens) é utilizada para agrupar zero ou mais declarações. O bloco é delimitado por um par de chavetas (“chavetas { }”) e opcionalmente poderá ser {{jsxref("Statements/label", "labelled", "", 1)}}:</p>
+
+<div>{{EmbedInteractiveExample("pages/js/statement-block.html", "taller")}}</div>
+
+
+
+<h2 id="Sintaxe">Sintaxe</h2>
+
+<h3 id="Declaração_de_Bloco">Declaração de Bloco</h3>
+
+<pre class="syntaxbox">{
+ <em>StatementList</em>
+}
+</pre>
+
+<h3 id="Declaração_de_Bloco_Etiquetado">Declaração de Bloco Etiquetado</h3>
+
+<pre class="syntaxbox"><em>LabelIdentifier</em>: {
+ <em>StatementList</em>
+}
+</pre>
+
+<dl>
+ <dt><code>StatementList</code></dt>
+ <dd>Statements grouped within the block statement.</dd>
+ <dt><code>LabelIdentifier</code></dt>
+ <dd>An optional {{jsxref("Statements/label", "label", "", 1)}} for visual identification or as a target for {{jsxref("Statements/break", "break")}}.</dd>
+</dl>
+
+<h2 id="Descrição">Descrição</h2>
+
+<p>The block statement is often called <strong>compound statement</strong> in other languages. It allows you to use multiple statements where JavaScript expects only one statement. Combining statements into blocks is a common practice in JavaScript. The opposite behavior is possible using an <a href="/en-US/docs/Web/JavaScript/Reference/Statements/Empty">empty statement</a>, where you provide no statement, although one is required.</p>
+
+<p>Blocks are commonly used in association with {{jsxref("Statements/if...else", "if...else")}} and {{jsxref("Statements/for", "for")}} statements.</p>
+
+<h3 id="Block_Scoping_Rules">Block Scoping Rules</h3>
+
+<h4 id="With_var_or_function_declaration_in_non-strict_mode">With <code>var</code> or function declaration in non-strict mode</h4>
+
+<p>Variables declared with <code>var</code> or created by <a href="/en-US/docs/Web/JavaScript/Reference/Statements/function">function declarations</a> in non-strict mode <strong>do not</strong> have block scope. Variables introduced within a block are scoped to the containing function or script, and the effects of setting them persist beyond the block itself. In other words, block statements do not introduce a scope. For example:</p>
+
+<pre class="brush: js example-bad">var x = 1;
+{
+ var x = 2;
+}
+console.log(x); // logs 2
+</pre>
+
+<p>This logs 2 because the <code>var x</code> statement within the block is in the same scope as the <code>var x</code> statement before the block.</p>
+
+<p>In non-strict code, function declarations inside blocks behave strangely. Do not use them.</p>
+
+<h4 id="With_let_const_or_function_declaration_in_strict_mode">With <code>let</code>, <code>const</code> or function declaration in strict mode</h4>
+
+<p>By contrast, identifiers declared with {{jsxref("Statements/let", "let")}} and {{jsxref("Statements/const", "const")}} <strong>do have </strong>block scope:</p>
+
+<pre class="brush: js">let x = 1;
+{
+ let x = 2;
+}
+console.log(x); // logs 1</pre>
+
+<p>The <code>x = 2</code> is limited in scope to the block in which it was defined.</p>
+
+<p>The same is true of <code>const</code>:</p>
+
+<pre class="brush: js">const c = 1;
+{
+ const c = 2;
+}
+console.log(c); // logs 1 and does not throw SyntaxError...</pre>
+
+<p>Note that the block-scoped <code>const c = 2</code> <em>does not</em> throw a <code>SyntaxError: Identifier 'c' has already been declared</code> because it can be declared uniquely within the block.</p>
+
+<p>In <a href="/en-US/docs/Web/JavaScript/Reference/Strict_mode">strict mode</a>, starting with ES2015, functions inside blocks are scoped to that block. Prior to ES2015, block-level functions were forbidden in strict mode.</p>
+
+<h2 id="Especificações">Especificações</h2>
+
+<table class="standard-table">
+ <thead>
+ <tr>
+ <th scope="col">Especificação</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td>{{SpecName('ESDraft', '#sec-block', 'Block statement')}}</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="Compatibilidade_de_navegador">Compatibilidade de navegador</h2>
+
+
+
+<p>{{Compat("javascript.statements.block")}}</p>
+
+<h2 id="Consulte_também">Consulte também</h2>
+
+<ul>
+ <li>{{jsxref("Statements/while", "while")}}</li>
+ <li>{{jsxref("Statements/if...else", "if...else")}}</li>
+ <li>{{jsxref("Statements/let", "let")}}</li>
+</ul>
diff --git a/files/pt-pt/web/javascript/reference/extratos_e_declarações/for/index.html b/files/pt-pt/web/javascript/reference/extratos_e_declarações/for/index.html
new file mode 100644
index 0000000000..ac7586e98b
--- /dev/null
+++ b/files/pt-pt/web/javascript/reference/extratos_e_declarações/for/index.html
@@ -0,0 +1,145 @@
+---
+title: for
+slug: Web/JavaScript/Reference/Extratos_e_declarações/for
+tags:
+ - Declaração
+ - Funcionalidade de Linguagem
+ - JavaScript
+ - Loop
+ - Referencia
+ - Repetição
+ - for
+translation_of: Web/JavaScript/Reference/Statements/for
+---
+<div>{{jsSidebar("Statements")}}</div>
+
+<p>A <strong>declaração "for"</strong> cria uma repetição (<em>loop</em>) que consiste de três expressões opcionais, entre parênteses e separados por ponto e vírgula, seguido de uma declaração (normalmente <a href="/pt-PT/docs/Web/JavaScript/Reference/Extratos_e_declarações/bloco">bdeclaraçãod e bloco (<em>block</em>)</a>) para ser executada na repetição.</p>
+
+<div>{{EmbedInteractiveExample("pages/js/statement-for.html")}}</div>
+
+
+
+<h2 id="Sintaxe">Sintaxe</h2>
+
+<pre class="syntaxbox">for ([<em>initialization</em>]; [<em>condition</em>]; [<em>final-expression</em>])
+ <em>statement</em></pre>
+
+<dl>
+ <dt><code>initialization</code></dt>
+ <dd>An expression (including assignment expressions) or variable declaration evaluated once before the loop begins. Typically used to initialize a counter variable. This expression may optionally declare new variables with <code>var</code> or <code>let</code> keywords. Variables declared with <code>var</code> are not local to the loop, i.e. they are in the same scope the <code>for</code> loop is in. Variables declared with let are local to the statement.</dd>
+ <dd>The result of this expression is discarded.</dd>
+ <dt><code>condition</code></dt>
+ <dd>An expression to be evaluated before each loop iteration. If this expression evaluates to true, <code>statement</code> is executed. This conditional test is optional. If omitted, the condition always evaluates to true. If the expression evaluates to false, execution skips to the first expression following the <code>for</code> construct.</dd>
+ <dt><code>final-expression</code></dt>
+ <dd>An expression to be evaluated at the end of each loop iteration. This occurs before the next evaluation of <code>condition</code>. Generally used to update or increment the counter variable.</dd>
+ <dt><code>statement</code></dt>
+ <dd>A statement that is executed as long as the condition evaluates to true. To execute multiple statements within the loop, use a {{jsxref("Statements/block", "block", "", 0)}} statement (<code>{ ... }</code>) to group those statements. To execute no statement within the loop, use an {{jsxref("Statements/empty", "empty", "", 0)}} statement (<code>;</code>).</dd>
+</dl>
+
+<h2 id="Exemplos">Exemplos</h2>
+
+<h3 id="Using_for">Using <code>for</code></h3>
+
+<p>The following <code>for</code> statement starts by declaring the variable <code>i</code> and initializing it to <code>0</code>. It checks that <code>i</code> is less than nine, performs the two succeeding statements, and increments <code>i</code> by 1 after each pass through the loop.</p>
+
+<pre class="brush: js">for (let i = 0; i &lt; 9; i++) {
+ console.log(i);
+ // more statements
+}
+</pre>
+
+<h3 id="Optional_for_expressions">Optional <code>for</code> expressions</h3>
+
+<p>All three expressions in the head of the <code>for</code> loop are optional.</p>
+
+<p>For example, in the <em>initialization</em> block it is not required to initialize variables:</p>
+
+<pre class="brush: js">var i = 0;
+for (; i &lt; 9; i++) {
+ console.log(i);
+ // more statements
+}
+</pre>
+
+<p>Like the <em>initialization</em> block, the <em>condition</em> block is also optional. If you are omitting this expression, you must make sure to break the loop in the body in order to not create an infinite loop.</p>
+
+<pre class="brush: js">for (let i = 0;; i++) {
+ console.log(i);
+ if (i &gt; 3) break;
+ // more statements
+}</pre>
+
+<p>You can also omit all three blocks. Again, make sure to use a {{jsxref("Statements/break", "break")}} statement to end the loop and also modify (increase) a variable, so that the condition for the break statement is true at some point.</p>
+
+<pre class="brush: js">var i = 0;
+
+for (;;) {
+ if (i &gt; 3) break;
+ console.log(i);
+ i++;
+}
+</pre>
+
+<h3 id="Using_for_without_a_statement">Using <code>for</code> without a statement</h3>
+
+<p>The following <code>for</code> cycle calculates the offset position of a node in the <em>final-expression</em> section, and therefore it does not require the use of a <code>statement</code> section, a semicolon is used instead.</p>
+
+<pre class="brush: js">function showOffsetPos(sId) {
+
+ var nLeft = 0, nTop = 0;
+
+ for (
+
+ var oItNode = document.getElementById(sId); /* initialization */
+
+ oItNode; /* condition */
+
+ nLeft += oItNode.offsetLeft, nTop += oItNode.offsetTop, oItNode = oItNode.offsetParent /* final-expression */
+
+ ); /* semicolon */
+
+ console.log('Offset position of \'' + sId + '\' element:\n left: ' + nLeft + 'px;\n top: ' + nTop + 'px;');
+
+}
+
+/* Example call: */
+
+showOffsetPos('content');
+
+// Output:
+// "Offset position of "content" element:
+// left: 0px;
+// top: 153px;"</pre>
+
+<div class="note"><strong>Note:</strong> This is one of the few cases in JavaScript where <strong>the semicolon is mandatory</strong>. Indeed, without the semicolon the line that follows the cycle declaration will be considered a statement.</div>
+
+<h2 id="Especificações">Especificações</h2>
+
+<table class="standard-table">
+ <tbody>
+ <tr>
+ <th scope="col">Especificação</th>
+ </tr>
+ <tr>
+ <td>{{SpecName('ESDraft', '#sec-for-statement', 'for statement')}}</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="Compatibilidade_de_navegador">Compatibilidade de navegador</h2>
+
+
+
+<p>{{Compat("javascript.statements.for")}}</p>
+
+<h2 id="Consulte_também">Consulte também</h2>
+
+<ul>
+ <li>{{jsxref("Statements/empty", "empty statement", "", 0)}}</li>
+ <li>{{jsxref("Statements/break", "break")}}</li>
+ <li>{{jsxref("Statements/continue", "continue")}}</li>
+ <li>{{jsxref("Statements/while", "while")}}</li>
+ <li>{{jsxref("Statements/do...while", "do...while")}}</li>
+ <li>{{jsxref("Statements/for...in", "for...in")}}</li>
+ <li>{{jsxref("Statements/for...of", "for...of")}}</li>
+</ul>
diff --git a/files/pt-pt/web/javascript/reference/extratos_e_declarações/index.html b/files/pt-pt/web/javascript/reference/extratos_e_declarações/index.html
new file mode 100644
index 0000000000..af841906a1
--- /dev/null
+++ b/files/pt-pt/web/javascript/reference/extratos_e_declarações/index.html
@@ -0,0 +1,150 @@
+---
+title: Declarações e instruções
+slug: Web/JavaScript/Reference/Extratos_e_declarações
+tags:
+ - JavaScript
+ - Referencia
+ - declarações
+ - instruções
+translation_of: Web/JavaScript/Reference/Statements
+---
+<div>{{jsSidebar("Statements")}}</div>
+
+<p>JavaScript applications consist of statements with an appropriate syntax. A single statement may span multiple lines. Multiple statements may occur on a single line if each statement is separated by a semicolon. This isn't a keyword, but a group of keywords.</p>
+
+<h2 id="Declarações_e_instruções_por_categoria">Declarações e instruções por categoria</h2>
+
+<p>For an alphabetical listing see the sidebar on the left.</p>
+
+<h3 id="Controlo_de_Fluxo">Controlo de Fluxo</h3>
+
+<dl>
+ <dt>{{jsxref("Statements/block", "Block")}}</dt>
+ <dd>A block statement is used to group zero or more statements. The block is delimited by a pair of curly brackets.</dd>
+ <dt>{{jsxref("Statements/break", "break")}}</dt>
+ <dd>Terminates the current loop, switch, or label statement and transfers program control to the statement following the terminated statement.</dd>
+ <dt>{{jsxref("Statements/continue", "continue")}}</dt>
+ <dd>Terminates execution of the statements in the current iteration of the current or labeled loop, and continues execution of the loop with the next iteration.</dd>
+ <dt>{{jsxref("Statements/Empty", "Empty")}}</dt>
+ <dd>An empty statement is used to provide no statement, although the JavaScript syntax would expect one.</dd>
+ <dt>{{jsxref("Statements/if...else", "if...else")}}</dt>
+ <dd>Executes a statement if a specified condition is true. If the condition is false, another statement can be executed.</dd>
+ <dt>{{jsxref("Statements/switch", "switch")}}</dt>
+ <dd>Evaluates an expression, matching the expression's value to a case clause, and executes statements associated with that case.</dd>
+ <dt>{{jsxref("Statements/throw", "throw")}}</dt>
+ <dd>Throws a user-defined exception.</dd>
+ <dt>{{jsxref("Statements/try...catch", "try...catch")}}</dt>
+ <dd>Marks a block of statements to try, and specifies a response, should an exception be thrown.</dd>
+</dl>
+
+<h3 id="Declarações">Declarações</h3>
+
+<dl>
+ <dt>{{jsxref("Statements/var", "var")}}</dt>
+ <dd>Declares a variable, optionally initializing it to a value.</dd>
+ <dt>{{jsxref("Statements/let", "let")}}</dt>
+ <dd>Declares a block scope local variable, optionally initializing it to a value.</dd>
+ <dt>{{jsxref("Statements/const", "const")}}</dt>
+ <dd>Declares a read-only named constant.</dd>
+</dl>
+
+<h3 id="Funções_e_classes">Funções e classes</h3>
+
+<dl>
+ <dt>{{jsxref("Statements/function", "function")}}</dt>
+ <dd>Declara as funções com parâmetros especificados.</dd>
+ <dt>{{jsxref("Statements/function*", "function*")}}</dt>
+ <dd>Generators functions enable writing <a href="/en-US/docs/Web/JavaScript/Guide/The_Iterator_protocol">iterators</a> more easily.</dd>
+ <dt>{{jsxref("Statements/async_function", "async function")}}</dt>
+ <dd>Declares an async function with the specified parameters.</dd>
+ <dt>{{jsxref("Statements/return", "return")}}</dt>
+ <dd>Specifies the value to be returned by a function.</dd>
+ <dt>{{jsxref("Statements/class", "class")}}</dt>
+ <dd>Declara uma Classe.</dd>
+</dl>
+
+<h3 id="Iterações">Iterações</h3>
+
+<dl>
+ <dt>{{jsxref("Statements/do...while", "do...while")}}</dt>
+ <dd>Creates a loop that executes a specified statement until the test condition evaluates to false. The condition is evaluated after executing the statement, resulting in the specified statement executing at least once.</dd>
+ <dt>{{jsxref("Statements/for", "for")}}</dt>
+ <dd>Creates a loop that consists of three optional expressions, enclosed in parentheses and separated by semicolons, followed by a statement executed in the loop.</dd>
+ <dt>{{deprecated_inline}} {{non-standard_inline()}} {{jsxref("Statements/for_each...in", "for each...in")}}</dt>
+ <dd>Iterates a specified variable over all values of object's properties. For each distinct property, a specified statement is executed.</dd>
+ <dt>{{jsxref("Statements/for...in", "for...in")}}</dt>
+ <dd>Iterates over the enumerable properties of an object, in arbitrary order. For each distinct property, statements can be executed.</dd>
+ <dt>{{jsxref("Statements/for...of", "for...of")}}</dt>
+ <dd>Iterates over iterable objects (including {{jsxref("Global_Objects/Array","arrays","","true")}}, array-like objects, <a href="/en-US/docs/JavaScript/Guide/Iterators_and_Generators">iterators and generators</a>), invoking a custom iteration hook with statements to be executed for the value of each distinct property.</dd>
+ <dt>{{jsxref("Statements/while", "while")}}</dt>
+ <dd>Creates a loop that executes a specified statement as long as the test condition evaluates to true. The condition is evaluated before executing the statement.</dd>
+</dl>
+
+<h3 id="Outros">Outros</h3>
+
+<dl>
+ <dt>{{jsxref("Statements/debugger", "debugger")}}</dt>
+ <dd>Invokes any available debugging functionality. If no debugging functionality is available, this statement has no effect.</dd>
+ <dt>{{jsxref("Statements/export", "export")}}</dt>
+ <dd>Used to export functions to make them available for imports in external modules, another scripts.</dd>
+ <dt>{{jsxref("Statements/import", "import")}}</dt>
+ <dd>Used to import functions exported from an external module, another script.</dd>
+ <dt><code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import.meta">import.meta</a></code></dt>
+ <dd>A meta-property exposing context-specific metadata to a JavaScript module.</dd>
+ <dt>{{jsxref("Statements/label", "label")}}</dt>
+ <dd>Provides a statement with an identifier that you can refer to using a <code>break</code> or <code>continue</code> statement.</dd>
+</dl>
+
+<dl>
+ <dt>{{deprecated_inline}} {{jsxref("Statements/with", "with")}}</dt>
+ <dd>Extends the scope chain for a statement.</dd>
+</dl>
+
+<h2 id="Especificações">Especificações</h2>
+
+<table class="standard-table">
+ <tbody>
+ <tr>
+ <th scope="col">Especificação</th>
+ <th scope="col">Estado</th>
+ <th scope="col">Comentário</th>
+ </tr>
+ <tr>
+ <td>{{SpecName('ES1', '#sec-12', 'Statements')}}</td>
+ <td>{{Spec2('ES1')}}</td>
+ <td>Initial definition</td>
+ </tr>
+ <tr>
+ <td>{{SpecName('ES3', '#sec-12', 'Statements')}}</td>
+ <td>{{Spec2('ES3')}}</td>
+ <td> </td>
+ </tr>
+ <tr>
+ <td>{{SpecName('ES5.1', '#sec-12', 'Statements')}}</td>
+ <td>{{Spec2('ES5.1')}}</td>
+ <td> </td>
+ </tr>
+ <tr>
+ <td>{{SpecName('ES6', '#sec-ecmascript-language-statements-and-declarations', 'ECMAScript Language: Statements and Declarations')}}</td>
+ <td>{{Spec2('ES6')}}</td>
+ <td>New: function*, let, for...of, yield, class</td>
+ </tr>
+ <tr>
+ <td>{{SpecName('ESDraft', '#sec-ecmascript-language-statements-and-declarations', 'ECMAScript Language: Statements and Declarations')}}</td>
+ <td>{{Spec2('ESDraft')}}</td>
+ <td> </td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="Compatibilidade_de_navegador">Compatibilidade de navegador</h2>
+
+
+
+<p>{{Compat("javascript.statements")}}</p>
+
+<h2 id="Consultar_também">Consultar também</h2>
+
+<ul>
+ <li><a href="/pt-PT/docs/Web/JavaScript/Reference/Operadores">Operadores</a></li>
+</ul>
diff --git a/files/pt-pt/web/javascript/reference/extratos_e_declarações/return/index.html b/files/pt-pt/web/javascript/reference/extratos_e_declarações/return/index.html
new file mode 100644
index 0000000000..6cec134992
--- /dev/null
+++ b/files/pt-pt/web/javascript/reference/extratos_e_declarações/return/index.html
@@ -0,0 +1,148 @@
+---
+title: return
+slug: Web/JavaScript/Reference/Extratos_e_declarações/return
+tags:
+ - Declaração
+ - JavaScript
+translation_of: Web/JavaScript/Reference/Statements/return
+---
+<div>{{jsSidebar("Statements")}}</div>
+
+<p>The <strong><code>return</code> statement</strong> ends function execution and specifies a value to be returned to the function caller.</p>
+
+<h2 id="Sintaxe">Sintaxe</h2>
+
+<pre class="syntaxbox">return [[expression]]; </pre>
+
+<dl>
+ <dt><code>expression</code></dt>
+ <dd>The expression whose value is to be returned. If omitted, <code>undefined</code> is returned instead.</dd>
+</dl>
+
+<h2 id="Descrição">Descrição</h2>
+
+<p>When a <code>return</code> statement is used in a function body, the execution of the function is stopped. If specified, a given value is returned to the function caller. For example, the following function returns the square of its argument, <code>x</code>, where <code>x</code> is a number.</p>
+
+<pre class="brush: js">function square(x) {
+ return x * x;
+}
+var demo = square(3);
+// demo will equal 9
+</pre>
+
+<p>If the value is omitted, <code>undefined</code> is returned instead.</p>
+
+<p>The following return statements all break the function execution:</p>
+
+<pre class="brush: js">return;
+return true;
+return false;
+return x;
+return x + y / 3;
+</pre>
+
+<h3 id="Inserção_Automática_de_Ponto_e_Vírgula">Inserção Automática de Ponto e Vírgula</h3>
+
+<p>The <code>return</code> statement is affected by <a href="/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#Automatic_semicolon_insertion">automatic semicolon insertion (ASI)</a>. No line terminator is allowed between the <code>return</code> keyword and the expression.</p>
+
+<pre class="brush: js">return
+a + b;
+</pre>
+
+<p>is transformed by ASI into:</p>
+
+<pre>return;
+a + b;
+</pre>
+
+<p>The console will warn "unreachable code after return statement".</p>
+
+<div class="note">Starting with Gecko 40 {{geckoRelease(40)}}, a warning is shown in the console if unreachable code is found after a return statement.</div>
+
+<h2 id="Exemplos">Exemplos</h2>
+
+<h3 id="Interromper_uma_função">Interromper uma função</h3>
+
+<p>A function immediately stops at the point where <code>return</code> is called.</p>
+
+<pre class="brush: js">function counter() {
+ for (var count = 1; ; count++) { // infinite loop
+ console.log(count + 'A'); // until 5
+ if (count === 5) {
+ return;
+ }
+ console.log(count + 'B'); // until 4
+ }
+ console.log(count + 'C'); // never appears
+}
+
+counter();
+
+// Output:
+// 1A
+// 1B
+// 2A
+// 2B
+// 3A
+// 3B
+// 4A
+// 4B
+// 5A
+</pre>
+
+<h3 id="Devolver_uma_função">Devolver uma função</h3>
+
+<p>See also the article about <a href="/en-US/docs/Web/JavaScript/Closures">Closures</a>.</p>
+
+<pre class="brush: js">function magic(x) {
+ return function calc(x) { return x * 42; };
+}
+
+var answer = magic();
+answer(1337); // 56154
+</pre>
+
+<h2 id="Especificações">Especificações</h2>
+
+<table class="standard-table">
+ <tbody>
+ <tr>
+ <th scope="col">Especificação</th>
+ <th scope="col">Estado</th>
+ <th scope="col">Comentário</th>
+ </tr>
+ <tr>
+ <td>{{SpecName('ES1')}}</td>
+ <td>{{Spec2('ES1')}}</td>
+ <td>Initial definition.</td>
+ </tr>
+ <tr>
+ <td>{{SpecName('ES5.1', '#sec-12.9', 'Return statement')}}</td>
+ <td>{{Spec2('ES5.1')}}</td>
+ <td> </td>
+ </tr>
+ <tr>
+ <td>{{SpecName('ES6', '#sec-return-statement', 'Return statement')}}</td>
+ <td>{{Spec2('ES6')}}</td>
+ <td> </td>
+ </tr>
+ <tr>
+ <td>{{SpecName('ESDraft', '#sec-return-statement', 'Return statement')}}</td>
+ <td>{{Spec2('ESDraft')}}</td>
+ <td> </td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="Compatibilidade_de_navegador">Compatibilidade de navegador</h2>
+
+
+
+<p>{{Compat("javascript.statements.return")}}</p>
+
+<h2 id="Consulte_também">Consulte também</h2>
+
+<ul>
+ <li><a href="/en-US/docs/Web/JavaScript/Reference/Functions_and_function_scope" title="En/Core_JavaScript_1.5_Reference/Functions">Functions</a></li>
+ <li><a href="/en-US/docs/Web/JavaScript/Closures">Closures</a></li>
+</ul>
diff --git a/files/pt-pt/web/javascript/reference/extratos_e_declarações/throw/index.html b/files/pt-pt/web/javascript/reference/extratos_e_declarações/throw/index.html
new file mode 100644
index 0000000000..9e7a8bf54e
--- /dev/null
+++ b/files/pt-pt/web/javascript/reference/extratos_e_declarações/throw/index.html
@@ -0,0 +1,271 @@
+---
+title: throw
+slug: Web/JavaScript/Reference/Extratos_e_declarações/throw
+tags:
+ - Comando
+ - Declaração
+ - JavaScript
+translation_of: Web/JavaScript/Reference/Statements/throw
+---
+<div>{{jsSidebar("Statements")}}</div>
+
+<p>A <strong>declaração <code>throw</code> </strong>lança uma exeção definida pelo utilizador. A execução da função atual irá parar (os comandos depois de <code>throw</code> não serão executados), <span id="result_box" lang="pt"><span>e o controle será passado para o primeiro bloco <code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/try...catch">catch</a></code> no conjunto de chamadas. Se não existir nenhum bloco <code>catch</code> entre as funções de <em>caller</em>, o programa irá terminar.</span></span></p>
+
+<h2 id="Sintaxe">Sintaxe</h2>
+
+<pre class="syntaxbox">expressão throw; </pre>
+
+<dl>
+ <dt><code>expressão</code></dt>
+ <dd>A expressão para <em>throw</em>.</dd>
+</dl>
+
+<h2 id="Descrição">Descrição</h2>
+
+<p>Use the <code>throw</code> statement to throw an exception. When you throw an exception, <code>expression</code> specifies the value of the exception. Each of the following throws an exception:</p>
+
+<pre class="brush: js">throw 'Error2'; // generates an exception with a string value
+throw 42; // generates an exception with the value 42
+throw true; // generates an exception with the value true</pre>
+
+<p>Also note that the <code>throw</code> statement is affected by <a href="/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#Automatic_semicolon_insertion">automatic semicolon insertion (ASI)</a> as no line terminator between the <code>throw</code> keyword and the expression is allowed.</p>
+
+<h2 id="Exemplos">Exemplos</h2>
+
+<h3 id="Throw_um_objeto">Throw um objeto</h3>
+
+<p>You can specify an object when you throw an exception. You can then reference the object's properties in the <code>catch</code> block. The following example creates an object of type <code>UserException</code> and uses it in a <code>throw</code> statement.</p>
+
+<pre class="brush: js">function UserException(message) {
+ this.message = message;
+ this.name = 'UserException';
+}
+function getMonthName(mo) {
+ mo = mo - 1; // Adjust month number for array index (1 = Jan, 12 = Dec)
+ var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul',
+ 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
+ if (months[mo] !== undefined) {
+ return months[mo];
+ } else {
+ throw new UserException('InvalidMonthNo');
+ }
+}
+
+try {
+ // statements to try
+ var myMonth = 15; // 15 is out of bound to raise the exception
+ var monthName = getMonthName(myMonth);
+} catch (e) {
+ monthName = 'unknown';
+ console.log(e.message, e.name); // pass exception object to err handler
+}
+</pre>
+
+<h3 id="Outro_exemplo_de_throwing_um_objeto">Outro exemplo de <em>throwing</em> um objeto</h3>
+
+<p>The following example tests an input string for a U.S. zip code. If the zip code uses an invalid format, the throw statement throws an exception by creating an object of type <code>ZipCodeFormatException</code>.</p>
+
+<pre class="brush: js">/*
+ * Creates a ZipCode object.
+ *
+ * Accepted formats for a zip code are:
+ * 12345
+ * 12345-6789
+ * 123456789
+ * 12345 6789
+ *
+ * If the argument passed to the ZipCode constructor does not
+ * conform to one of these patterns, an exception is thrown.
+ */
+
+function ZipCode(zip) {
+ zip = new String(zip);
+ pattern = /[0-9]{5}([- ]?[0-9]{4})?/;
+ if (pattern.test(zip)) {
+ // zip code value will be the first match in the string
+ this.value = zip.match(pattern)[0];
+ this.valueOf = function() {
+ return this.value
+ };
+ this.toString = function() {
+ return String(this.value)
+ };
+ } else {
+ throw new ZipCodeFormatException(zip);
+ }
+}
+
+function ZipCodeFormatException(value) {
+ this.value = value;
+ this.message = 'does not conform to the expected format for a zip code';
+ this.toString = function() {
+ return this.value + this.message;
+ };
+}
+
+/*
+ * This could be in a script that validates address data
+ * for US addresses.
+ */
+
+const ZIPCODE_INVALID = -1;
+const ZIPCODE_UNKNOWN_ERROR = -2;
+
+function verifyZipCode(z) {
+ try {
+ z = new ZipCode(z);
+ } catch (e) {
+ if (e instanceof ZipCodeFormatException) {
+ return ZIPCODE_INVALID;
+ } else {
+ return ZIPCODE_UNKNOWN_ERROR;
+ }
+ }
+ return z;
+}
+
+a = verifyZipCode(95060); // returns 95060
+b = verifyZipCode(9560); // returns -1
+c = verifyZipCode('a'); // returns -1
+d = verifyZipCode('95060'); // returns 95060
+e = verifyZipCode('95060 1234'); // returns 95060 1234
+</pre>
+
+<h3 id="Rethrow_uma_exceção"><em>Rethrow</em> uma exceção</h3>
+
+<p>You can use <code>throw</code> to rethrow an exception after you catch it. The following example catches an exception with a numeric value and rethrows it if the value is over 50. The rethrown exception propagates up to the enclosing function or to the top level so that the user sees it.</p>
+
+<pre class="brush: js">try {
+ throw n; // throws an exception with a numeric value
+} catch (e) {
+ if (e &lt;= 50) {
+ // statements to handle exceptions 1-50
+ } else {
+ // cannot handle this exception, so rethrow
+ throw e;
+ }
+}
+</pre>
+
+<h2 id="Especificações">Especificações</h2>
+
+<table class="standard-table">
+ <tbody>
+ <tr>
+ <th scope="col">Especificação</th>
+ <th scope="col">Estado</th>
+ <th scope="col">Comentário</th>
+ </tr>
+ <tr>
+ <td>{{SpecName('ES3')}}</td>
+ <td>{{Spec2('ES3')}}</td>
+ <td>Initial definition. Implemented in JavaScript 1.4</td>
+ </tr>
+ <tr>
+ <td>{{SpecName('ES5.1', '#sec-12.13', 'throw statement')}}</td>
+ <td>{{Spec2('ES5.1')}}</td>
+ <td> </td>
+ </tr>
+ <tr>
+ <td>{{SpecName('ES6', '#sec-throw-statement', 'throw statement')}}</td>
+ <td>{{Spec2('ES6')}}</td>
+ <td> </td>
+ </tr>
+ <tr>
+ <td>{{SpecName('ESDraft', '#sec-throw-statement', 'throw statement')}}</td>
+ <td>{{Spec2('ESDraft')}}</td>
+ <td> </td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="Compatibilidade_de_navegador">Compatibilidade de navegador</h2>
+
+
+
+<p>{{Compat("javascript.statements.throw")}}</p>
+
+<h2 id="Consulte_também">Consulte também</h2>
+
+<ul>
+ <li><a href="/pt-PT/docs/Web/JavaScript/Reference/Extratos_e_declarações/try...catch"><code>try...catch</code></a></li>
+</ul>
+
+<div id="SL_balloon_obj" style="display: block;">
+<div class="SL_ImTranslatorLogo" id="SL_button" style="background: rgba(0, 0, 0, 0) repeat scroll 0% 0%; opacity: 0; display: block; left: -8px; top: -25px; transition: visibility 2s ease 0s, opacity 2s linear 0s;"> </div>
+
+<div id="SL_shadow_translation_result2" style="display: none;"> </div>
+
+<div id="SL_shadow_translator" style="display: none;">
+<div id="SL_planshet">
+<div id="SL_arrow_up" style="background: rgba(0, 0, 0, 0) repeat scroll 0% 0%;"> </div>
+
+<div id="SL_Bproviders">
+<div class="SL_BL_LABLE_ON" id="SL_P0" title="Google">G</div>
+
+<div class="SL_BL_LABLE_ON" id="SL_P1" title="Microsoft">M</div>
+
+<div class="SL_BL_LABLE_ON" id="SL_P2" title="Translator">T</div>
+</div>
+
+<div id="SL_alert_bbl" style="display: none;">
+<div id="SLHKclose" style="background: rgba(0, 0, 0, 0) repeat scroll 0% 0%;"> </div>
+
+<div id="SL_alert_cont"> </div>
+</div>
+
+<div id="SL_TB">
+<table id="SL_tables">
+ <tbody><tr>
+ <td class="SL_td"><input></td>
+ <td class="SL_td"><select><option value="auto">Detectar idioma</option><option value="af">Africâner</option><option value="sq">Albanês</option><option value="de">Alemão</option><option value="ar">Arabe</option><option value="hy">Armênio</option><option value="az">Azerbaijano</option><option value="eu">Basco</option><option value="bn">Bengali</option><option value="be">Bielo-russo</option><option value="my">Birmanês</option><option value="bs">Bósnio</option><option value="bg">Búlgaro</option><option value="ca">Catalão</option><option value="kk">Cazaque</option><option value="ceb">Cebuano</option><option value="ny">Chichewa</option><option value="zh-CN">Chinês (Simp)</option><option value="zh-TW">Chinês (Trad)</option><option value="si">Cingalês</option><option value="ko">Coreano</option><option value="ht">Crioulo haitiano</option><option value="hr">Croata</option><option value="da">Dinamarquês</option><option value="sk">Eslovaco</option><option value="sl">Esloveno</option><option value="es">Espanhol</option><option value="eo">Esperanto</option><option value="et">Estoniano</option><option value="fi">Finlandês</option><option value="fr">Francês</option><option value="gl">Galego</option><option value="cy">Galês</option><option value="ka">Georgiano</option><option value="el">Grego</option><option value="gu">Gujarati</option><option value="ha">Hauça</option><option value="iw">Hebraico</option><option value="hi">Hindi</option><option value="hmn">Hmong</option><option value="nl">Holandês</option><option value="hu">Húngaro</option><option value="ig">Igbo</option><option value="id">Indonésio</option><option value="en">Inglês</option><option value="yo">Ioruba</option><option value="ga">Irlandês</option><option value="is">Islandês</option><option value="it">Italiano</option><option value="ja">Japonês</option><option value="jw">Javanês</option><option value="kn">Kannada</option><option value="km">Khmer</option><option value="lo">Laosiano</option><option value="la">Latim</option><option value="lv">Letão</option><option value="lt">Lituano</option><option value="mk">Macedônico</option><option value="ml">Malaiala</option><option value="ms">Malaio</option><option value="mg">Malgaxe</option><option value="mt">Maltês</option><option value="mi">Maori</option><option value="mr">Marathi</option><option value="mn">Mongol</option><option value="ne">Nepalês</option><option value="no">Norueguês</option><option value="fa">Persa</option><option value="pl">Polonês</option><option value="pt">Português</option><option value="pa">Punjabi</option><option value="ro">Romeno</option><option value="ru">Russo</option><option value="sr">Sérvio</option><option value="st">Sesotho</option><option value="so">Somália</option><option value="sw">Suaíli</option><option value="su">Sudanês</option><option value="sv">Sueco</option><option value="tg">Tadjique</option><option value="tl">Tagalo</option><option value="th">Tailandês</option><option value="ta">Tâmil</option><option value="cs">Tcheco</option><option value="te">Telugo</option><option value="tr">Turco</option><option value="uk">Ucraniano</option><option value="ur">Urdu</option><option value="uz">Uzbeque</option><option value="vi">Vietnamita</option><option value="yi">Yiddish</option><option value="zu">Zulu</option></select></td>
+ <td class="SL_td">
+ <div id="SL_switch_b" style="background: rgba(0, 0, 0, 0) repeat scroll 0% 0%;" title="Alternar Idiomas"> </div>
+ </td>
+ <td class="SL_td"><select><option value="af">Africâner</option><option value="sq">Albanês</option><option value="de">Alemão</option><option value="ar">Arabe</option><option value="hy">Armênio</option><option value="az">Azerbaijano</option><option value="eu">Basco</option><option value="bn">Bengali</option><option value="be">Bielo-russo</option><option value="my">Birmanês</option><option value="bs">Bósnio</option><option value="bg">Búlgaro</option><option value="ca">Catalão</option><option value="kk">Cazaque</option><option value="ceb">Cebuano</option><option value="ny">Chichewa</option><option value="zh-CN">Chinês (Simp)</option><option value="zh-TW">Chinês (Trad)</option><option value="si">Cingalês</option><option value="ko">Coreano</option><option value="ht">Crioulo haitiano</option><option value="hr">Croata</option><option value="da">Dinamarquês</option><option value="sk">Eslovaco</option><option value="sl">Esloveno</option><option value="es">Espanhol</option><option value="eo">Esperanto</option><option value="et">Estoniano</option><option value="fi">Finlandês</option><option value="fr">Francês</option><option value="gl">Galego</option><option value="cy">Galês</option><option value="ka">Georgiano</option><option value="el">Grego</option><option value="gu">Gujarati</option><option value="ha">Hauça</option><option value="iw">Hebraico</option><option value="hi">Hindi</option><option value="hmn">Hmong</option><option value="nl">Holandês</option><option value="hu">Húngaro</option><option value="ig">Igbo</option><option value="id">Indonésio</option><option selected value="en">Inglês</option><option value="yo">Ioruba</option><option value="ga">Irlandês</option><option value="is">Islandês</option><option value="it">Italiano</option><option value="ja">Japonês</option><option value="jw">Javanês</option><option value="kn">Kannada</option><option value="km">Khmer</option><option value="lo">Laosiano</option><option value="la">Latim</option><option value="lv">Letão</option><option value="lt">Lituano</option><option value="mk">Macedônico</option><option value="ml">Malaiala</option><option value="ms">Malaio</option><option value="mg">Malgaxe</option><option value="mt">Maltês</option><option value="mi">Maori</option><option value="mr">Marathi</option><option value="mn">Mongol</option><option value="ne">Nepalês</option><option value="no">Norueguês</option><option value="fa">Persa</option><option value="pl">Polonês</option><option value="pt">Português</option><option value="pa">Punjabi</option><option value="ro">Romeno</option><option value="ru">Russo</option><option value="sr">Sérvio</option><option value="st">Sesotho</option><option value="so">Somália</option><option value="sw">Suaíli</option><option value="su">Sudanês</option><option value="sv">Sueco</option><option value="tg">Tadjique</option><option value="tl">Tagalo</option><option value="th">Tailandês</option><option value="ta">Tâmil</option><option value="cs">Tcheco</option><option value="te">Telugo</option><option value="tr">Turco</option><option value="uk">Ucraniano</option><option value="ur">Urdu</option><option value="uz">Uzbeque</option><option value="vi">Vietnamita</option><option value="yi">Yiddish</option><option value="zu">Zulu</option></select></td>
+ <td class="SL_td">
+ <div id="SL_TTS_voice" style="background: rgba(0, 0, 0, 0) repeat scroll 0% 0%;" title="Ouça"> </div>
+ </td>
+ <td class="SL_td">
+ <div class="SL_copy" id="SL_copy" style="background: rgba(0, 0, 0, 0) repeat scroll 0% 0%;" title="Copiar"> </div>
+ </td>
+ <td class="SL_td">
+ <div id="SL_bbl_font_patch"> </div>
+
+ <div class="SL_bbl_font" id="SL_bbl_font" style="background: rgba(0, 0, 0, 0) repeat scroll 0% 0%;" title="Tamanho da fonte"> </div>
+ </td>
+ <td class="SL_td">
+ <div id="SL_bbl_help" style="background: rgba(0, 0, 0, 0) repeat scroll 0% 0%;" title="Ajuda"> </div>
+ </td>
+ <td class="SL_td">
+ <div class="SL_pin_off" id="SL_pin" style="background: rgba(0, 0, 0, 0) repeat scroll 0% 0%;" title="Fixar a janela de pop-up"> </div>
+ </td>
+ </tr>
+</tbody></table>
+</div>
+</div>
+
+<div id="SL_shadow_translation_result" style=""> </div>
+
+<div class="SL_loading" id="SL_loading" style="background: rgba(0, 0, 0, 0) repeat scroll 0% 0%;"> </div>
+
+<div id="SL_player2"> </div>
+
+<div id="SL_alert100">A função de fala é limitada a 200 caracteres</div>
+
+<div id="SL_Balloon_options" style="background: rgb(255, 255, 255) repeat scroll 0% 0%;">
+<div id="SL_arrow_down" style="background: rgba(0, 0, 0, 0) repeat scroll 0% 0%;"> </div>
+
+<table id="SL_tbl_opt" style="width: 100%;">
+ <tbody><tr>
+ <td><input></td>
+ <td>
+ <div id="SL_BBL_IMG" style="background: rgba(0, 0, 0, 0) repeat scroll 0% 0%;" title="Mostrar o botão do ImTranslator 3 segundos"> </div>
+ </td>
+ <td><a class="SL_options" title="Mostrar opções">Opções</a> : <a class="SL_options" title="Histórico de tradução">Histórico</a> : <a class="SL_options" title="Comentários">Comentários</a> : <a class="SL_options" href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&amp;hosted_button_id=GD9D8CPW8HFA2" title="Faça sua contribuição">Donate</a></td>
+ <td><span id="SL_Balloon_Close" title="Encerrar">Encerrar</span></td>
+ </tr>
+</tbody></table>
+</div>
+</div>
+</div>