In what year did Brendan Eich create JavaScript at Netscape?
Answer : 1995
Brendan Eich designed JavaScript in 1995 at Netscape, in about ten days. The language has no kinship with Java, despite the name.
Revise JavaScript & TypeScript: here is a selection of questions of every level, with the answer and an explanation. To test yourself without seeing the answers, play the quizzes.
Play the JavaScript & TypeScript quizzesAnswer : 1995
Brendan Eich designed JavaScript in 1995 at Netscape, in about ten days. The language has no kinship with Java, despite the name.
Answer : let
let declares a block-scoped variable that can be reassigned. const forbids reassignment, and var has function scope.
Answer : string
The typeof operator returns a string describing the type of the value: for a string of characters, the result is string.
Answer : true
The == operator compares after conversion: '0' becomes the number 0. With === the types must also be identical, and the result would be false.
Answer : length
The length property gives the number of elements of an array: [1, 2, 3].length is 3.
Answer : querySelector
querySelector accepts any CSS selector and returns the first element found, or null if none matches.
Answer : Register a function that is called when an event occurs
addEventListener attaches a function to an element for an event type, such as a click. The function is called each time the event occurs.
Answer : JSON.stringify
JSON.stringify turns a JavaScript value into JSON text; JSON.parse does the opposite.
Answer : ES6 (ECMAScript 2015)
ES6, published in 2015, introduced let and const, arrow functions and classes.
Answer : undefined
With var, the declaration is hoisted but not the assignment: x already exists, with the value undefined. With let, the same access throws a ReferenceError.
Answer : That of the enclosing function, set where the function is written
An arrow function has no own this: it takes the this of the place where it is defined.
Answer : A function that keeps access to the variables of the scope where it was created
A closure keeps access to the variables of the enclosing function, even after that function has finished running.
Answer : undefined
undefined is the value of a variable declared without assignment. null represents an absence of value chosen explicitly by the programmer.
Answer : [2, 4]
filter keeps the elements for which the function returns true: here the even numbers.
Answer : A promise that will be resolved with the value 10
The resolution value of then is the result of the callback function: here 5 multiplied by 2, that is 10.
Answer : Always a promise
An async function always returns a promise: the return value is wrapped, and an exception becomes a rejection.
Answer : 2012
TypeScript, led by Anders Hejlsberg, was published by Microsoft in October 2012: it is a typed superset of JavaScript.
Answer : An unknown value must be checked before use, whereas any disables this check
any disables type checking on the value. unknown forces you to narrow the type before any use, which protects the code.
Answer : It keeps the type of the received argument and returns it unchanged
T is a type variable: TypeScript infers it from the argument at each call, which keeps the precise type of the result.
Answer : Structure: what the object has matters, not the declared name
TypeScript is structural: an object is compatible if it has the expected properties with the right types, even without an explicit declaration.
Answer : The microtask queue, such as promises
Promise callbacks form the microtask queue, which the loop empties completely between two tasks. Macrotasks, such as setTimeout, are processed one at a time.
Answer : In the prototype of the object, then along the prototype chain
The lookup climbs the prototype chain. If the property exists nowhere, the value read is undefined, without an error.
Answer : strict
strict: true enables notably strictNullChecks and noImplicitAny. Each of these options can also be set separately.
Answer : npm
npm reads the package.json file and installs the dependencies in the node_modules folder.
Play the JavaScript & TypeScript quizzes