Generalities Flashcards
How to loop over elements of an array without using an index ?
for(let x of array) {
// use x
}
What is the difference between an expression and a statement ?
Basically, expressions represent anything that is a value or that will produce a value.
A statement is a task, an order. In general the statement modify the state of the computer. And expression can produce a value without modifying the state of the computer.
A statement is formed by one or many expressions. A statement can also itself be an expression.
How are called the functions defined using the shorthand syntax of ES6 ?
Arrow functions
What is a litteral ?
It is a data value that appears directly in the program.
Examples:
12
1.2
“Hello World”
‘Hi’
true
false
null
What are the authorize characters to begin an identifier in javascript ?
A letter, an underscore, a dollar sign.
What are the primitive types of javascript ?
number
string
boolean
null
undefined
symbol
bigint
What are the object types of javascript ?
object
functions (and classes)
What are the special kinds of objects (non fundamentals one) defined by Javascript ?
Arrays,
Set,
Map,
Typed Arrays,
RegExp
Date
Error
Even more specials: functions and classes
What does untyped mean in “Constants and variables are untyped”
It means that their declarations do not specify the kind/type of values that will be assigned.
How to write BigInt Litterals ?
As a string of digits followed by the letter ‘n’
What are the differencies between BigInt and Numbers ?
- BigInt are arbitrary precision, Numbers have the limits imposed by IEEE754
- Numbers can represent floating point numbers and BigInt can only represent Integers
- Both types cannot be mixed in arithmetic operations
With the type Date, how to get a string representing the current date in long format ?
Date()
With the type Date, how to get an object representing the current date ?
new Date()
With the type Date, how to get a timestamp representing the current date (number of milliseconds since Jan 1st 1970) ?
Date.now()
or
(new Date()).getTime()
With the type Date, how to get a string representing the current date in long ISO standard format ?
(new Date()).toISOString()
With strings, what is the difference between
for(let x of aString) {
// use x
}
and
for(let i=0; i<aString.length; i++) {
// use aString[i]
}
the first method iterate on unicode characters, the second iterate on 16bit elements of the string. The difference is that some unicode characters may require more than 1 16bit element in the string. These characters will be returned in 2 iterations with the second method.
It is possible to compare strings with equality (===) or inequality (!==) operators in javascript. True or False
True
What are the differences between for..in and for..of in javascript ?
for in loops over enumerable property names of an object.
for of (new in ES6) does use an object-specific iterator and loops over the values generated by that.
What does \b means in javascript regex ?
The \b metacharacter matches at the beginning or end of a word.
Search for the pattern LO at the beginning of a word like this:
\bLO
Search for the pattern LO at the end of a word like this:
LO\b
In js, how to search a regex in a string with methods of the regex object ?
pattern.test(text) => return true or false
pattern.exec(text) => return null or an array. The first elt of the array is the matching string.
In js, how to search a regex in a string with methods of the string object ?
text.search(pattern) // => 9: position of first match
text.match(pattern) // => [“1”, “2”, “3”]: array of all matches
What are the falsy values of Javascript ?
undefined
null
0
-0
NaN
“” // the empty string
false
What are the truthy values in javascript ?
All the values that are not one of the 7 falsy values.
WWhat are the differences between null and undefined ?
- null is a keyword, undefined is a constant
- typeof null == “object” (for historical reason) and typeof undefined == “undefined”
- null has to be explicitly set. Undefined is the default value when a variable, a constant, a property, etc has not been initialized
- In a conversion to Number, null converts to 0 and undefined converts to NaN