Javascript (Hack Reactor) Flashcards
What does ‘NaN’ mean?
Not A Number
i.e. “I think you meant to have a number here, but I cannot produce a number with what you gave me, so have NaN instead :)
Data types (8)
Scalar:
(1) Number
(2) BigInt
(3) String
(4) Boolean (logical type)
(5) null
(6) undefined
(7) Objects and (8) Symbols
How to format a string to be replaced with variables?
Use backticks
` random text ${variable} here `
What is the difference in formatting a string with variable replacements in JS and formatting a string in Python?
In Python we format strings using f strings e.g.
f’random text {variable} here’
In JS we use backticks and preface variable replacement with $
` random text ${variable} here `
Method to find the length of a string?
string.length
How to format if else statement?
if (cond) {
// code to execute
} else {
// code to execute
}
How to format function?
function checkAge(age) {
# code
}
How to specify a line as a comment?
Preface with // (forward slashes)
How to delete the key and value of an object?
delete obj[key]
How to access the value of an object?
bracket notation
obj[key]
Does NULL == undefined?
No, these are different data types
In what two scenarios would ‘undefined’ be returned?
- when we do not specify what should be returned in our function
- variable declared at but not assigned a value
Booleans in JS vs booleans in Python
lowercase true or false
Python, the booleans are capitalised True or False
Which equality operator should we use to err on the side of caution?
triple equals
How to express these operators:
and
or
symbols
&&
||