JavaScript / TypeScript

Here is a quiz about “Web Development”.

At the end of the quiz, you’ll see your result. Retry the wrong answer(s) to discover the right one(s).

Warning

If your score is below average, call SED immediately ! 😆. Seriously, please come and talk with us to avoid doing major mistakes.

The button provides some help !

--- primary_color: steelblue --- ## Introduction Which of the following accurately describes the difference between JavaScript and TypeScript? - [ ] JavaScript is used for server-side programming, while TypeScript is used for client-side programming - [ ] JavaScript is a script language derived from Java, while Typescript is derived from C# - [ ] Typescript had been created with programming security in mind, especially type-related errors - [x] JavaScript is a dynamically typed language, while TypeScript is a statically typed superset of JavaScript ## Development What does the term "hoisting" refer to in JavaScript? - [ ] The process of automatically converting TypeScript code to JavaScript - [x] The mechanism by which JavaScript variables and function declarations are moved to the top of their respective scopes during the compilation phase - [ ] It's an option for the compilation phase that unlocks the optimizations - [ ] The practice of moving up a function into its enclosing scope during compilation phase ## Development What does the "typeof" operator in JavaScript do? - [ ] It checks whether a variable or expression is of the "object" type - [x] It returns the data type of a given variable or expression - [ ] It compares the values of two variables or expressions for equality - [ ] It converts a value to a boolean data type ## Development Which in the following statements describe the most accurately TypeScript interfaces ? - [ ] It's used for purely documentation purposes and have no impact on the code that is run - [ ] It's a runtime construct that is used to create objects - [ ] It's a set of conventions that enables inter-process communications through the API specified by the interface - [x] It's a synctatical contract that help to define the shape of objects, classes or function types ## Development Which TypeScript keyword is used to declare a variable with a specific type? - [ ] let - [ ] const - [ ] var - [x] type ## Code : types management What is the output of the following TypeScript code ? ```typescript const num: number = 5; console.log(num.toString()); ``` - [ ] `5` - [x] `"5"` - [ ] `Error` - [ ] `undefined` ## Code : arrays What is the output of the following Javascript code ? ```javascript [1, 2, 3, 4, 5, 6, 7].map( v => { v + 1 } ) ``` - [ ] `SyntaxError` - [ ] `[ 2, 3, 4, 5, 6, 7, 8 ]` - [ ] `[ ]` - [x] `[ undefined,undefined,undefined,undefined,undefined,undefined,undefined ]` ## Code : arrays What is the output of the following Javascript code ? ```javascript [1, 2, 3, 4, 5, 6, 7].filter(v => v%2 === 0) ``` - [ ] `SyntaxError` - [ ] `[ undefined, undefined, undefined ]` - [ ] `[ ]` - [x] `[ 2, 4, 6 ]` ## Code : Js equality test tricks Which of the following propositions are true ? > More than 1 good answers - [x] '1' == true - [x] '' == false - [x] '1' == 1 - [ ] '1' === 1 ## Code : Js equality test tricks Which of the following propositions are true ? Note: all "0" are the *zero* digit > More than 1 good answers - [x] 0 == "0" - [x] 0 == [] - [ ] "0" == [] - [x] 0 == false ## Code : Js equality test tricks What is the output of the following code ? ```javascript let result = null == undefined ``` - [x] `true` - [ ] `false` - [ ] `Error` - [ ] `undefined` ## Code : Ts typing tricks What is the output of the following typescript code ? ```javascript let result = 2 + 2 + '5' ``` - [x] `"45"` - [ ] `9` - [ ] `Error` - [ ] `undefined` ## Code : Ts typing tricks What is the output of the following typescript code ? ```typescript let arr: Array = [10, 20, 30]; console.log(arr + 40); ``` - [ ] `Error` - [ ] `undefined` - [ ] `[ 10, 20, 30, 40 ]` - [x] `"10,20,3040"` ## Code : Ts typing tricks What is the output of the following typescript code ? ```typescript const name: string = "John"; console.log('Hello, ${name}!'); ``` - [ ] `"Hello, John!"` - [ ] `Error` - [ ] `"Hello, undefined!"` - [x] `"Hello, ${name}!"` ## Code : Ts typing tricks What is the output of the following typescript code ? ```typescript let num1: any = "5"; let num2: number = 10; let result: number = num1 + num2; ``` - [ ] `15` - [ ] `NaN` - [x] `"510"` - [ ] `Error` ## Code : Promises What is the output of the following javascript code ? ```javascript function fetchData() { return new Promise((r) => { r('DATA')}) }; console.log(fetchData()); ``` - [x] `Promise {}` - [ ] `Promise {: "DATA"}` - [ ] `Error` - [ ] `"DATA"` ## Code : Promises What is the output of the following snippet of code ? ```javascript function fetchData() { return new Promise((r) => { setTimeout(() => { r('DATA'); }, 1000); }); } const result = fetchData(); console.log(result); result.then((data) => { console.log(data); }); (async function f() { console.log('SLEEP 1'); const result = await new Promise(r => setTimeout(r('SLEEP 2'), 2000)); console.log(result); })(); console.log('FINISHED'); ``` - [x] ``` Promise { } SLEEP 1 FINISHED DATA SLEEP 2 ``` - [ ] ``` DATA Promise { : "DATA" } SLEEP 1 SLEEP 2 FINISHED ``` - [ ] ``` Promise { } DATA SLEEP 1 Promise { : SLEEP 2 } FINISHED ``` - [ ] ``` Promise { } Promise { : "DATA" } SLEEP 1 Promise { : "SLEEP 2" } FINISHED ``` ## Code : function call Which of the following code snippets will return `A` ? > More than 1 good answer - [ ] ```javascript const f = () => { return 'A' }; console.log(f);``` - [x] ```javascript const a = (function f() { return 'A' })(); console.log(a);``` - [x] ```javascript console.log( ( () => 'A' )());``` - [x] ```javascript const a = function f() { return Promise.resolve('A') }; console.log(a());``` ## Code : JS classes and `this` keyword What is the output of the following code snippet ? ```javascript function Person(name) { this.name = name; } Person.prototype.greet = function() { console.log(`Hello, ${this.name}!`); }; const john = new Person('John'); const greet = john.greet; greet(); ``` - [ ] `"TypeError: greet is not a function"` - [ ] `"TypeError: Cannot read property 'greet' of undefined"` - [ ] `"Hello John"` - [x] `"Hello undefined"` ## Code : JS Objects What is the output of the following code snippet ? ```javascript const person = { name: 'Bob', age: 30, hobbies: ['reading', 'gaming'] }; const clonedPerson = { ...person }; clonedPerson.name = 'Alice'; clonedPerson.hobbies.push('coding'); console.log(`${person.name}` : `${person.hobbies}`); ``` - [x] `"Bob : [ 'reading', 'gaming', 'coding' ]` - [ ] `"Bob : [ 'reading', 'gaming' ]` - [ ] `"Alice : [ 'reading', 'gaming', 'coding' ]` - [ ] `"Alice : [ 'reading', 'gaming' ]` ## Code : ES Modules What is the output of the following code snippet ? ```javascript // moduleA.js export let count = 0; export function incrementCount() { count++; } // moduleB.js import { count, incrementCount } from './moduleA.js'; incrementCount(); console.log(count); ``` - [ ] `undefined` - [ ] `ReferenceError` - [x] `0` - [ ] `1`

The quiz only runs in your browser. Even if your score is bad ! 😉

No personnal datas about you or your score are kept. Only an anonymous ratio is store to help us to build future tutorials.