JavaScript Flashcards
scripts
programs that accompany web pages.
Run in web browsers and make web pages more dynamic and powerful
variables
should start with lower case letter
displays in browser console
console.log()
displays on the web page
document.write()
mark the end of a statement
semicolon
optional unless we write multiple statements in a single line
comments
// single line /*multi line*/
open the console
Ctrl + Shift + J
javascript
programming language of the web
create a variable
var name/identifier = value;
undefined
a value
maximum number of decimal places JavaScript can handle
17
to know what type of data a variable contains
console.log(typeof(variable’s name));
data types
string
numbers
Boolean
object
special kind of comparison operator that requires the value and the type to be equal
===
logical and
logical or
&&
||
assign a value to a variable based on a condition being true or false
conditional operator
?
if non-boolean values have real value except 0, “”, undefined
when converted condition returns true
perform different actions based on different condition
conditional statements
if, switch
concatenate strings
string.concat(string);
to find how many characters a string have
string.length;
escaping character
\
extract a piece of string
slice(start, end);
substr(start, length);
replace
string.replace(search string, replace string);
change a string to use lower/upper case letters
string. toLowerCase();
string. toUpperCase():
multiplication and devision with a non-numeric string result in
NaN
not a number
but its type is number
casting
parstInt(string);
parseFloat(string);
round a number
Math.round(number);
Math.random();
produces a random number between 0 and 1
Date
date.getFullYear();
date.getMonth();
date.getDate();
date.getDay(); returns week day as a number from 0 to 6
toDateString();
special kind of variable that contains several values of a type or even different types
array
great way to store related values
var array_name = [content];
[ ]
array litteral
turns an array into a comma-separated string
array. toString();
array. join();