Types and Grammar Flashcards
What is a type?
A type is an intrinsic build in set of characteristics that uniquely distinguishes the behavior
Javascripts built in types (7)
null undefined boolean number string object symbol
Except for objects, all JS types are called:
Primitives
Function is what type?
object. Specifically a “callable object”
function.length returns
the number of formal parameters is it declared with
Array is what type?
A subtype of object
typeof [“d”,”a”]
object
var a;
typeof a
undefined
undefined vs undeclared
Undefined has been defined in accessible scope but not defined. Undeclared hasn’t been declared.
var a = [] a["13"] = "hello"; What will happen?
a will be populated with undefined until a[13] which is hello
mutability of strings
immutable
mutability of arrays
mutable
with a decimal value of eg 0.42, is the 0 optional?
yes
With a decimal value of 42.30, is the 0 optional?
yes
Why is 0.1 + 0.2 == 0.3 false?
Binary floating point numbers are not exact. It’s actually like .300000000004. This is like a number epsilon.
Whats the best way to compare float calculations?
Use a tiny rounding error. See that a - b < Number.EPSILON
Can you create
var undefined in unstrict more?
yes
NaN is a type of
Number. eg var a = 1+"foo" typeof a === "number" >> true
How to check if a value is NaN and why?
isNaN(a)
We have to do this because NaN is a type of number
downfalls with isNaN
Literally checks if it is NaN. Strings return true for example instead of whether it is a NaN subtype
What can you do to check if it is type NaN?
var a = 3/"hello" Number.isNaN(a)
1/0 is
infinity