Comentários
// Comentário de uma única linha
/* Comentário
* para
* várias
* linhas
*/
É uma linguagem completa, inclusive tem orientação a objetos.
Conta com as estruturas: if, for, while, switch, etc.
Variáveis
Escopo: local e global
Funções
Pequeno exemplo de uso de objetos:
var pessoa = new Object();
pessoa.nome = "Ribamar";
pessoa.idade = 59;
pessoa.profissao = "Programador";
Outra forma:
var pessoa = {
nome: "Ribamar",
idade: 59,
profissao = "Programador",
digaNome: function(){
alert(this.nome);
}
};
var formacaoJava = {
sigla : " K10", nome : " Formação Desenvolvedor Java ",
cursos : [
{
sigla : "K11 ",
nome : " Orientação a Objetos em Java "
},
{
sigla : "K12 ",
nome : " Desenvolvimento Web com JSF2 e JPA2 "
},
]
};
Algumas Ferramentas
- Firebug é uma ótima extensão para o Firefox
- Netbeans para HTML5/JavaScript - http://netbeans.org
- Eclipse para JavaScript - http://www.eclipse.org/downloads/packages/eclipse-ide-javascript-web-developers/heliossr1
Apareceram vários frameworks sobre o JavaScript:
- AngularJS - https://angularjs.org/
- Backbone - http://backbonejs.org/
- TypeScript - https://www.typescriptlang.org/
Mais sobre JavaScript:
http://www.w3schools.com/JS/
JavaScript PopUp Boxes
With JavaScript you can create three types of PopUp boxes: Alert, Confirm and Prompt. In javaScript you can also manipulate browsers to create popup windows, but that is covered in a later tutorial.
Alert
An alert box is often used if you want to make sure information comes through to the user or during testing. A developer can use alerts to see how code is being interpreted. When an alert box pops up, the user will have to click "OK" to proceed.
<script type="text/javascript">
function disp_conf()
{
alert ("I am an alert box!!");
}
</script>
<input type="button" onclick="disp_alert()" value="Display Alert" />
Confirm Box
A confirm box is often used if you want the user to verify or accept something.. When a confirm box pops up, the user will have to click either "OK" or "Cancel" to proceed. If the user clicks "OK", the box returns true. If the user clicks "Cancel", the box returns false.
<script type="text/javascript">
function disp_confirm()
{
var x = confirm("Press a button");
if (x == true)
{
document.write("You pressed OK!");
}
else
{
document.write("You pressed Cancel!");
}
}
</script>
<input type="button" onclick="disp_confirm()" value="Display Confirm" />
Prompt Box
A prompt box is often used if you want the user to input a value before entering a page. When a prompt box pops up, the user will have to click either "OK" or "Cancel" to proceed after entering an input value. If the user clicks "OK" the box returns the input value. If the user clicks "Cancel" the box returns null.
<script type="text/javascript">
function disp_prompt()
{
var name=prompt("Please enter your name","Tutorials Fan");
if (name!=null && name != "")
{
document.write("Hello " + name + "! How are you today?");
}
}
</script>
<input type="button" onclick="disp_promt()" value="Display Prompt" />
Conclusão
PopUp boxes are simple to use, yet are an invaluable tool. As you start developing more complex code, you will see how wonderful an alert is to test if statements. Just remember there are three basic types of PopUp boxes: Alert, Confirm and Prompt. Think about using a prompt box as a way to ask for a password.
http://www.quackit.com/javascript/tutorial/javascript_popup_boxes.cfm
Comments fornecido por CComment