From 68fc8e96a9629e73469ed457abd955e548ec670c Mon Sep 17 00:00:00 2001 From: Florian Merz Date: Thu, 11 Feb 2021 14:49:58 +0100 Subject: unslug pt-br: move --- files/pt-br/learn/javascript/howto/index.html | 290 ++++++++++++++++++++++++++ 1 file changed, 290 insertions(+) create mode 100644 files/pt-br/learn/javascript/howto/index.html (limited to 'files/pt-br/learn/javascript/howto') diff --git a/files/pt-br/learn/javascript/howto/index.html b/files/pt-br/learn/javascript/howto/index.html new file mode 100644 index 0000000000..c06dbd4d3f --- /dev/null +++ b/files/pt-br/learn/javascript/howto/index.html @@ -0,0 +1,290 @@ +--- +title: Solve common problems in your JavaScript code +slug: Aprender/JavaScript/Howto +translation_of: Learn/JavaScript/Howto +--- +
{{LearnSidebar}}
+ +

Os links a seguir apontam soluções para problemas comuns do dia a dia, você precisará consertar em ordem para que seu código javascript execute corretamente.

+ +

Erros comuns de iniciantes

+ +

Digitação correta and casing

+ +

Se o seu código não funciona e/ou se seu navegador indicar que algo está indefinido, verifique se você declarou todas os nomes de suas variáveis, nomes de funções, etc. corretamente.

+ +

Algumas funções comuns dos navegadores que causam problema são:

+ + + + + + + + + + + + + + + + + + + + + + + + + + +
CorretoIncorreto
getElementsByTagName()getElementbyTagName()
getElementsByName()getElementByName()
getElementsByClassName()getElementByClassName()
getElementById()getElementsById()
+ +

Posições de ponto e vírgula

+ +

Você precisa ter certeza que você não colocou nenhum ponto e vírgula incorretamente. Por exemplo:

+ + + + + + + + + + + + +
CorrectWrong
elem.style.color = 'red';elem.style.color = 'red;'
+ +

Funções

+ +

Há uma série de coisas que podem dar errado com funções

+ +

Um dos erros mais comuns é declarar a função, mas não chama-la em lugar nenhum. Por exemplo:

+ +
function myFunction() {
+  alert('This is my function.');
+};
+ +

Este código não fará nada a menos que você o chame, por exemplo com

+ +
myFunction();
+ +

Escopo da função

+ +

Lembre-se que funções tem seu próprio escopo — você não pode acessar um conjunto de valores de variáveis ​​dentro de uma função fora da função, a não ser que você tenha declarado a variável globalmente (i.e. não dentro de nenhuma função), ou retorne o valor or retorne o valor fora da função

+ +

Executar o código antes de uma declaração de retorno

+ +

Remember also that when you return a value out of a function, the JavaScript interpreter exits the function — no code declared after the return statement will run.

+ +

In fact, some browsers (like Firefox) will give you an error message in the developer console if you have code after a return statement. Firefox gives you "unreachable code after return statement".

+ +

Object notation versus normal assignment

+ +

When you assign something normally in JavaScript, you use a single equals sign, e.g.:

+ +
var myNumber = 0;
+ +

This doesn't work in Objects, however — with objects you need to separate member names from their values using colons, and separate each member with a comma, for example:

+ +
var myObject = {
+  name : 'Chris',
+  age : 38
+}
+ +

Definições básicas

+ +
+ + + +
+ +

Casos de uso básicos

+ +
+ + +
+

Arrays

+ + + +

Debugging JavaScript

+ + + +

For more information on JavaScript debugging, see Handling common JavaScript problems; also see Other common errors for a description of common errors.

+ +

Making decisions in code

+ + + +

Looping/iteration

+ + +
+
+ +

Intermediate use cases

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