pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://developer.mozilla.org/pt-BR/docs/Learn_web_development/Howto/Solve_JavaScript_problems

precisará consertar em ordem para que seu código javascript execute corretamente." />

Esta página foi traduzida do inglês pela comunidade. Saiba mais e junte-se à comunidade MDN Web Docs.

View in English Always switch to English

Solve common problems in your JavaScript code

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:

Correto Incorreto
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:

Correct Wrong
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:

js
function myFunction() {
  alert("This is my function.");
}

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

js
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.:

js
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:

js
var myObject = {
  name: "Chris",
  age: 38,
};

Definições básicas

Casos de uso básicos

Geral

Variáveis

Matemática

Strings

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

Functions

Objects

JSON

Eventos

Javascript Orientado a objetos

Web APIs

pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy