A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://developer.mozilla.org/pt-BR/docs/Web/JavaScript/Reference/Errors/Stmt_after_return below:

Warning: unreachable code after return statement - JavaScript

Warning: unreachable code after return statement Mensagem
Warning: unreachable code after return statement (Firefox)
Tipo de Erro

Warning

O que deu errado?

Codigo inacessível depois da declaração de retorno pode ocorrer nas seguintes situações:

Quando existe uma expressão após uma declaração válida de return, um warning é dado para indicar que o código depois da declaração return é inacessível, significando que ele pode nunca ser executado.

Porque eu devo usar ponto-e-virgula após declarações return? No caso de declarações return sem ponto-e-vírgula, ele pode deixar obscuro se o desenvolvedor quis usar o return na proxima linha, ou parar a execução e retornar. O warning indica que há uma ambiguidade no modo que a declaração return foi escrita.

Warnings não serão mostrado para declarações return sem ponto-e-vírgula nas seguintes situações:

Exemplos Casos Inválidos
function f() {
  var x = 3;
  x += 4;
  return x; // return exits the function immediately
  x -= 3; // so this line will never run; it is unreachable
}

function f() {
  return; // this is treated like `return;`
  3 + 4; // so the function returns, and this line is never reached
}
Casos Válidos
function f() {
  var x = 3;
  x += 4;
  x -= 3;
  return x; // OK: return after all other statements
}

function f() {
  return 3 + 4; // OK: semicolon-less return with expression on the same line
}
Ver também

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4