Quick Review JavaScript
Quick Review JavaScript
</script>
Including Comments
Single line comments - //
VARIABLES IN JAVASCRIPT
Data Types
Numbers — var age = 23
Variables — var x
Operations — var b = 1 + 2 + 3
Constant numbers — const PI = 3.14
Objects
var person = {
firstName:"Jim",
lastName:"Stark",
age:29,
nationality:"German"
};
Array Methods
concat() — Join several arrays into one
OPERATORS
Basic Operators
+ — Addition
- — Subtraction
* — Multiplication
/ — Division
% — Modulus (remainder )
++ — Increment numbers
-- — Decrement numbers
Comparison Operators
== — Equal to
!= — Not equal
Logical Operators
&& — Logical and
|| — Logical or
! — Logical not
Bitwise Operators
& — AND statement
| — OR statement
~ — NOT
^ — XOR
FUNCTIONS
function name(parameter1, parameter2, parameter3) {
Outputting Data
alert() — Output data in an alert box in the browser window
Global Functions
STRINGS
var person = "John Doe";
Escape Characters
\' — Single quote
\\ — Backslash
\b — Backspace
\f — Form feed
\n — New line
\r — Carriage return
\t — Horizontal tabulator
\v — Vertical tabulator
String Methods
charAt() — Returns a character at a specified position inside a
string
charCodeAt() — Gives you the unicode of character at that position
Number Properties
MAX_VALUE — The maximum numeric value representable in JavaScript
Number Methods
toExponential() — Returns a string with a rounded number written as
exponential notation
IF - ELSE STATEMENTS
if (condition) {
// what to do if condition is met
} else {
}
JAVASCRIPT EVENTS
Mouse
onclick — The event occurs when the user clicks on an element
Form
onblur — When an element loses focus
onselect — The user selects some text (for <input> and <textarea>)