Variables & Types Flashcards
What is a template literal?
string literals allowing embedded expressions
i.e. string text ${expression} string text
What does string.raw() do?
It takes the complete string of a template literal and renders it raw, including any escaped or special characters.
What is the difference between let and const?
- Both are block scoped and you will receive a ReferenceError when accessing a variable before it’s declared
- Let can be reassigned while const cannot
What is the difference between let and var?
- let is block scoped while var is global / function scoped
- referencing var before it is defined will result in ‘undefined’
- referencing let before its defined with result in a ReferenceError.
What is the startsWith()
method?
- The startsWith() method determines whether a string begins with the characters of a specified string.
- Method is case sensitive
- Returns a boolean value.
string.startsWith (searchvalue, start) –> The start value is optional. If not specified, it starts at the beginning of the string. If specified, it will start at the index specified.
Example:
var str = “Hello world, welcome to the universe.”;
var n = str.startsWith(“world”, 6); returns true
What is the ends with()
method?
- Determines whether a string ends with the characters of a specified string.
- Case sensitive
- returns a boolean value
Syntax: string.endsWith(searchvalue, length)
where length is optional. It specified the length of the string to search from the start of the string.
var str = "Hello world, welcome to the universe."; var n = str.endsWith("world", 11); **returns true**
What is an example of a correct destructuring syntax for deconstructing an array?
var [Id, ApplicantName] = arr;
T/F: A template literal always has more strings than values
True
What is a Symbol in JavaScript?
- primitive data type
- the Symbol() function returns a value of type symbol
- A symbol value may be used as an identifier for object properties
- A globally unique, un-guessable value
What does Number.isSafeInteger(value) do?
Test if the value is and integer and falls between MIN_SAFE_INTEGER and MAX_SAFE_INTEGER