Typescript/Javascript ES6) Flashcards
What type of element can be hoisted to the top of the current scope
Variable declaration only; NOT declaration and assignment
How is a LET variable scoped
Block scoped; the current function or if or …
How is a VAR variable scoped
var is Function scoped.
When can you remove the parens in and arrow function declaration?
When there is only a single input parameter
How is sort() used WITH an input array?
sortedArr = numberArr.sort( (a,b) => a > b ? 1: -1);
Write the destructured assignment for:
x = [15, 07, 2015];
a = 15;
b = 07;
c = 2015;
var [a, b, c] = [15, 07, 2015]
Show assigning m and y from a function X( ) returning
{ d:15, m:07, y:2015}. Use destructuring.
var { , m, y } = X( );
Show assigning default values to function x( a, b);
function x( a = 1, b = “test”);
var course = { name: “javascript”, length: 15 };
function test(c) { let { first, second, third } = c; //destructure ... }
How can you make ‘third’ optional.
?third
JavaScript have following type of Comment(s).
A Single Line Comments
B Multiple Line Comments
C All of the above
D None of the above
C All of the above
Single Line Comments
Multiple Line Comments
Which of the following is considered as End of Single line comment ?
A End of Line
B End of Statement
C Semicolon
D None of the above
B End of Statement
Comments in JS are ignored by
A Compiler
B JVM
C Operating System
D Browser
A Compiler
Comment Statement is _____ type of statement.
A Non Important
B Non Executable
C Executive
D Non Usable
B Non Executable
Person XYZ wrote his name and date of code creation at the start. What kind of comment has he written ?
A Functional Comment
B Documentation Comment
C Code Hiding Comment
D None of the above
B Documentation Comment
Which of the following is not a compound assignment operator ?
A ===
B <<=
C +=
D >>=
A ===
operators that perform the specified operation on the right-side value before assigning a value to the left side.
x += y
x -= y
x *= y
x /= y
x %= y
bitwise:
(BitWise OR)
^ (Bitwise XOR)
~ (Bitwise Not)
<< (Left Shift)
>> (Right Shift)
>>> (Right shift with Zero)
Again, with = following, make operation occur on the right before assignment.
If a string cannot be converted to a number _____ will be returned.
A Infinite
B NaN
C Zero
D Null
B NaN
During addition of two numbers, suppose one of the number is NaN then output of the following code will be ?
A Infinite
B NaN
C Zero
D Null
B NaN
Integer Variable is declared using following syntax in JavaScript.
A integer num;
B Integer num;
C int num;
D counter num;
D counter num;
We can declare _____ at a time. Select the most appropriate option from the following four.
A More than One Variables
B One Variable Only
C One or more Variables
D None of the above
B One Variable Only
We can declare all type of variables in JavaScript with the keyword
A var
B obj
C jvar
D None of the above
A var
Show example of declaration of a tuple called role.
role: [number, string];
Max claims you can have more fields?
Show declaration of enum type.
enum Role { ADMIN = 5, READ_ONLY, AUTHOR }
Show use of an enum called ROLE used to declare ‘role’ type variable.
role: Role.ADMIN
let x : Function; Will this compile and run?
Yes
Define a variable declaration that is a function with no input parameters and returns a number.
This can later be assigned to a Function that takes 0 parameters and returns a number type.
let combine: () => number;
Define a variable declaration that is a function with two input parameters and returns a number.
This can later be assigned to a Function that takes 2 parameters and returns a number type.
let combine: (a: number, b: number) => number;
Will the following work:
Declaration:
function addAndHandle(n1: number, n2: number, cb: (num: number) =\> void) { const result = n1 + n2; cb(result); };
Reference:
addAndHandle(10, 20, (result: number) => {
console.log(result);
}
yes – it is a callback function example