Primitive Types Module #17 Flashcards
How would you define a number using hexadecimal syntax?
Start with the 0x prefix.
How would you convert $10.00 so that the calculations are dependably exact?
Multiply by 100 ( 10 x 100 = 1000 ) Stripe uses this method and essentially dollar values are calculated in pennies. .01 === 1
How can you test for a “type” of a variable?
Use the "typeof" keyword. For example: const age = Number( 36 ) typeof age //number
How can an you create an object from a number type?
Use the "new" keyword in front of the number. For Example: const age = new Number ( 36 ) typeof age //object
What can you use to determine the original number value of an object?
METHOD
Use the value of method. Example:
age.valueOf ( )
Define EPSILON.
EPSILON is the smallest interval between two numbers.
Define MAX_SAFE_INTEGER.
MAX_SAFE_INTEGER is the maximum integer value JavaScript can represent.
Define MAX_VALUE.
MAX_VALUE is the maximum positive value that JavaScript can represent.
Define MIN_SAFE_INTEGER.
MIN_SAFE_INTEGER is the minimum integer value JavaScript can represent.
Define MIN_VALUE.
MIN_VALUE is the minimum positive value JavaScript can represent.
Define NaN
A special value representing “not a number”.
METHODS: How is the NaN method expressed in JavaScript?
Number.isNaN(value) returns true if value is not a number
METHODS: How is the finite number method expressed?
Number.isFinite(value): returns true if value is a finite number.
METHODS: How is the integer method expressed ?
METHOD
Number.isInteger(value): returns true if value is an integer.
METHODS: How is the “safe” integer method expressed ?
METHOD
Number.isSafeInteger(value): returns true if value is a safe integer.
METHODS: How is the floating point number method expressed?
Number.parseFloat(value): converts value to a floating point number and returns it.
METHODS: How is the value of a floating point number converted into an integer expressed as a method?
Number.parseInt(value): converts value to an integer and returns it. It can also convert strings with words, extracting the first number, but the string must start with a number.
What kinds of methods can you use on a “Number Object”?
.toExponential( ), .toFixed( ), .toLocaleString( ), .toPrecision( ), .toString( ), .valueOf( )
What’s another way to define a string other than quotes? What’s it called?
By using backticks
this is called a template literal. This relieves the need to escape double or single quotes with backslashes.
How would you insert a variable or expression into a string?
“By using ${ dollarsign-curly brace syntax with backticks arouund it all } Inside the braces you can add any JS expression.”
What is charAt( i )
It is a method that returns the character at the position of i in a string. Examples: "Flavio".charAt(0) //'F' "Flavio".charAt(1) //'l' "Flavio".charAt(2) //'a'
What is concat (str)? What does it do?
Concatenates the current string with the string str. For example:
“Flavio”.concat(“ “).concat(“Copes”) //’Flavio Copes’
What does endsWith(str) do?
Check if a string ends with the value of the string str. Example:
“JavaScript”.endsWith(“Script”) //true
“JavaScript”.endsWith(“script”) //false
What does includes(str) do?
Check if a string includes the value of the string str.
“JavaScript”.includes(“Script”) //true
“JavaScript”.includes(“script”) //false
“JavaScript”.includes(“JavaScript”) //true
“JavaScript”.includes(“aSc”) //true
“JavaScript”.includes(“C++”) //false
includes() also accepts an optional second parameter, an integer which indicates the position where to start searching for:
“a nice string”.includes(“nice”) //true
“a nice string”.includes(“nice”, 3) //false
“a nice string”.includes(“nice”, 2) //true