Basic Syntax Flashcards
JS: console.log()
‘Print’ to screen
JS: .length
Return the length of a string variable
JS: . toUpperCase()
Change string to capitals
JS: . startsWith(n)
Returns a Boolean depending on your input value -(n)
JS: .trim()
Removes white space!
Also trimEnd or trimStart
JS: Math.random()
Return a random number between 0 and <1
JS: Math.floor()
Round down a decimal to nearest int
JS: Math.ceil(Math.random() * n);
Round up a decimal to nearest int with random number gen
JS: Number.isInteger()
Checks variable (number) and Returns a Boolean
What are the 7 fundamental data types in JS?
Strings
Numbers
Booleans
Null
Undefined
Symbol
Object
JS: let var =
const var. =
Use to assign a variable
JS: let
Signals a variable can be reassigned a new value
JS: const
Assign an immutable variable
JS: some string with ${someVar) included
;
String interpolating (bit like a python f-string)
JS: typeof
Eg. console.log(typeof myVar);
To return the data type of the stored value.
JS: if (condition) {
//execute this code
} else {
// execute this code
}
Basic conditional
JS: What’s the ‘and’ operator
&&
JS: What’s the ‘or’ operator?
||
JS: What’s the ‘not’ operator?
!
JS: Give the ‘falsy’ values.
0 , “” , null, undefined, NaN
JS: let VAR = VAR || ‘fresh input’
Short circuit evaluation
JS: VAR ? execute code : execute code;
Ternary operator
Checks if VAR is true then else