Escolar Documentos
Profissional Documentos
Cultura Documentos
Examples:
JavaScript Keywords
JavaScript statements often start with a keyword to identify the JavaScript action to be
performed.
Here is a list of some of the keywords you will learn about in this tutorial:
JavaScript Arithmetic Operators
Arithmetic operators are used to perform arithmetic on numbers:
These are commonly used special characters that can be inserted in a text
with the backslash sign:
Global Methods
JavaScript global methods can be used on all JavaScript data types.
These are the most relevant methods, when working with numbers:
Number Properties
Math Object Methods
Objects
ARRAYS
Comparison Operators
Comparison operators are used in logical statements to determine equality or
difference between variables or values.
Logical Operators
Logical operators are used to determine the logic between variables or
values.
Given that x = 6 and y = 3, the table below explains the logical operators:
When comparing a string with a number, JavaScript will convert the string to
a number when doing the comparison. An empty string converts to 0. A non-
numeric string converts to NaN which is always false.
Syntax
string
number
boolean
object
function
Object
Date
Array
undefined
Bitwise XOR
When a bitwise XOR is performed on a pair of bits, it returns 1 if the bits are
different:
The technical term for this is: JavaScript will throw an exception (throw
an error).
If you use throw together with try and catch, you can control program flow
and generate custom error messages.
The error object provides two useful properties: name and message.
Code Debugging
Programming code might contain syntax errors, or logical errors.
Often, when programming code contains errors, nothing will happen. There
are no error messages, and you will get no indications where to search for
errors.
JavaScript Debuggers
Debugging is not easy. But fortunately, all modern browsers have a built-in
JavaScript debugger.
With a debugger, you can also set breakpoints (places where code execution
can be stopped), and examine variables while the code is executing.
Normally, otherwise follow the steps at the bottom of this page, you activate
debugging in your browser with the F12 key, and select "Console" in the
debugger menu.
With the debugger turned on, this code will stop executing before it executes
the third line.
JavaScript Declarations are Hoisted
In JavaScript, a variable can be declared after it has been used.
You should also avoid using the name of HTML and Window objects and
properties:
Constraint Validation HTML Input
Attributes
Exemplo
Sometimes we like to have an "object type" that can be used to create many
objects of one type.
Syntax
Metodo
In other words: The HTML DOM is a standard for how to get, change,
add, or delete HTML elements.
JavaScript - HTML DOM
Methods
The getElementById Method
Later, in HTML DOM Level 3, more objects, collections, and properties were
added.
Finding HTML Element by Id
The easiest way to find an HTML element in the DOM, is by using the element
id.
IMAGE
JavaScript HTML DOM -
Changing CSS
Changing HTML Style
To change the style of an HTML element, use this syntax: