Podcast
Questions and Answers
Given the following code snippet, what will be the value of a
and b
after the code is executed?
let a = 111;
let b = 999;
const obj = { a: 23, b: 7, c: 14 };
({ a, b } = obj);
Given the following code snippet, what will be the value of a
and b
after the code is executed?
let a = 111;
let b = 999;
const obj = { a: 23, b: 7, c: 14 };
({ a, b } = obj);
- a = 23, b = 999
- a = 23, b = 7 (correct)
- a = 111, b = 7
- a = 111, b = 999
In JavaScript, the spread operator(...) can be used for passing separated data of an ________ into a function.
In JavaScript, the spread operator(...) can be used for passing separated data of an ________ into a function.
array
Consider the following JavaScript code:
const nested = [1, [2, 3], 4];
const [a, [b, c], d] = nested;
console.log(a, b, c, d);
What will be the output of console.log(a, b, c, d)
?
Consider the following JavaScript code:
const nested = [1, [2, 3], 4];
const [a, [b, c], d] = nested;
console.log(a, b, c, d);
What will be the output of console.log(a, b, c, d)
?
- 1, 2, 3, 4 (correct)
- 1, 2, undefined, 4
- Error: Invalid destructuring assignment
- 1, [2, 3], undefined, 4
The spread operator (...) can be used to create a deep copy of an object in JavaScript.
The spread operator (...) can be used to create a deep copy of an object in JavaScript.
Describe how array destructuring can be used to swap the values of two variables a
and b
in JavaScript. Include a brief code example.
Describe how array destructuring can be used to swap the values of two variables a
and b
in JavaScript. Include a brief code example.
Given the following code:
const HP = ['harry','hermion','ron',...['dambeldor','Snape','mackgolagan']]; const [name,...rest] = HP;
What will console.log(rest)
output?
Given the following code:
const HP = ['harry','hermion','ron',...['dambeldor','Snape','mackgolagan']]; const [name,...rest] = HP;
What will console.log(rest)
output?
The spread operator can be used on non-iterable objects directly without creating a new array.
The spread operator can be used on non-iterable objects directly without creating a new array.
Explain the difference between the ||
operator and the ??
(nullish coalescing) operator in JavaScript, particularly focusing on what values they consider 'falsy'.
Explain the difference between the ||
operator and the ??
(nullish coalescing) operator in JavaScript, particularly focusing on what values they consider 'falsy'.
In the context of function parameters, the ______ parameter must always be the last one defined.
In the context of function parameters, the ______ parameter must always be the last one defined.
Match the operator with its description:
Match the operator with its description:
What is the index and value that will be logged to the console for the second element in the following code snippet?
const arr = ['Newt', 'Tina', 'Jacob Kowalski', 'Queenie']; for(const item of arr.entries()) {console.log(item)}
What is the index and value that will be logged to the console for the second element in the following code snippet?
const arr = ['Newt', 'Tina', 'Jacob Kowalski', 'Queenie']; for(const item of arr.entries()) {console.log(item)}
In enhanced object literals, the shorthand for assigning a property named seasons
with the value of the variable seasons
is simply _________
.
In enhanced object literals, the shorthand for assigning a property named seasons
with the value of the variable seasons
is simply _________
.
Consider the following code:
const seasonNum = [1,2,3,4,5]; const seasons = { [seasonNum]: { episode: 13, realeased: {First: '20 September 2008', Last: '13 December 2008'} } };
What does seasons[seasonNum].episode
evaluate to?
Consider the following code:
const seasonNum = [1,2,3,4,5]; const seasons = { [seasonNum]: { episode: 13, realeased: {First: '20 September 2008', Last: '13 December 2008'} } };
What does seasons[seasonNum].episode
evaluate to?
The following code snippet will cause an error because the seasonNum array is used as a property key:
const seasonNum =[1,2,3,4,5]; const seasons = { [seasonNum]: { episode:13, realeased:{First:'20 September 2008 ', Last:'13 December 2008'} } };
The following code snippet will cause an error because the seasonNum array is used as a property key:
const seasonNum =[1,2,3,4,5]; const seasons = { [seasonNum]: { episode:13, realeased:{First:'20 September 2008 ', Last:'13 December 2008'} } };
In the serie
object, how is the getInfo
method defined using ES6 syntax, and what does it log to the console?
In the serie
object, how is the getInfo
method defined using ES6 syntax, and what does it log to the console?
Which of the following statements accurately describes the behavior of the nullish coalescing operator (??
) in JavaScript, as demonstrated by the example serie.risoto?.(10,12) ?? console.log('the method does not exist');
?
Which of the following statements accurately describes the behavior of the nullish coalescing operator (??
) in JavaScript, as demonstrated by the example serie.risoto?.(10,12) ?? console.log('the method does not exist');
?
Given the code:
const openinghours = {
sat: { open: '10 am', close: '10 pm' },
sun: { open: '11 am', close: '9 pm' },
mon: { open: '6 am', close: '12 pm', shift: 'harry' }
};
const values = Object.values(Object.keys(Object.values(openinghours)));
console.log(values);
The values
variable will contain an array of the opening and closing times for each day.
Given the code:
const openinghours = {
sat: { open: '10 am', close: '10 pm' },
sun: { open: '11 am', close: '9 pm' },
mon: { open: '6 am', close: '12 pm', shift: 'harry' }
};
const values = Object.values(Object.keys(Object.values(openinghours)));
console.log(values);
The values
variable will contain an array of the opening and closing times for each day.
Explain how the concept of optional chaining (?.
) and nullish coalescing (??
) operators can be combined to safely access nested object properties and provide a default value if the property is missing.
Explain how the concept of optional chaining (?.
) and nullish coalescing (??
) operators can be combined to safely access nested object properties and provide a default value if the property is missing.
In JavaScript, the Object.entries()
method returns an array of a given object's own enumerable string-keyed property ______
, in the format [key, value]
.
In JavaScript, the Object.entries()
method returns an array of a given object's own enumerable string-keyed property ______
, in the format [key, value]
.
Match the following JavaScript code snippets with their described outcomes:
Match the following JavaScript code snippets with their described outcomes:
Flashcards
Array Destructuring
Array Destructuring
A feature to unpack values from arrays into distinct variables.
Default Values in Destructuring
Default Values in Destructuring
Assign default values when the array elements are undefined.
Swapping Variables
Swapping Variables
Use destructuring to swap values of two variables easily.
Returning Multiple Values
Returning Multiple Values
Signup and view all the flashcards
Spread Operator
Spread Operator
Signup and view all the flashcards
Rest Parameter
Rest Parameter
Signup and view all the flashcards
Nullish Coalescing Operator
Nullish Coalescing Operator
Signup and view all the flashcards
Logical Assignment Operators
Logical Assignment Operators
Signup and view all the flashcards
For...of Loop
For...of Loop
Signup and view all the flashcards
Array.entries()
Array.entries()
Signup and view all the flashcards
Computed Property Names
Computed Property Names
Signup and view all the flashcards
Enhanced Object Literals
Enhanced Object Literals
Signup and view all the flashcards
Optional Chaining
Optional Chaining
Signup and view all the flashcards
Method Shorthand
Method Shorthand
Signup and view all the flashcards
Looping Objects
Looping Objects
Signup and view all the flashcards
Set Data Structure
Set Data Structure
Signup and view all the flashcards
Map Data Structure
Map Data Structure
Signup and view all the flashcards
Object.entries()
Object.entries()
Signup and view all the flashcards
Study Notes
Array Destructuring
- ES6 feature: Allows extracting values from arrays into distinct variables.
- Example:
const arr = [1, 2, 3]; const [x, y, z] = arr;
- Skipping elements:
const [a, , c] = arr;
skips the second element. - Default values:
const [a = 10, b = 20, c = 30] = numbers;
provides default values if the array is shorter.
Default Values
- Setting Defaults: Assign default values to array elements.
- Example: Setting default values for elements that don't exist.
Nested Arrays
- Destructuring: Extracting elements from nested arrays.
- Example:
const nested = [1, [2, 3], 4]; const [a, [b, c], d] = nested;
Destructuring Objects
- Swapping/Mutating Data: Allows swapping variables or changing data.
- Example:
let a = 111; let b = 999; [a, b] = [b, a];
swaps the values ofa
andb
. - Example:
const obj = {a: 23, b: 7, c: 14 }; {a, b} = obj;
- Mutating Objects:
const obj = {a:23,b:7,c=14}; a= 25
Returning Multiple Values
- From a Function: Functions can return multiple values as an array.
- Destructuring: Extract the returned values into variables.
- Example:
function getMultipleValues() { return [10, 20, 30]; }; const [a, b, c] = getMultipleValues();
Spread Operator
- Passing separated data: Use the spread operator (
...
) to pass separated array data into a function. - Example:
const orders = ['salad', 'kebab', 'cola']; restaurantOrder(...orders);
- Copying arrays: Creates a shallow copy of an array
const otherOrder =['donat','pizza','abali'];
,const copyOfOtherOrder = [...otherOrder];
- Concatenating arrays: Combines two arrays
const allOrders = [...otherOrder, ...orders];
Object Literals
- Enhanced Literals: Computed property names to create objects from variable values.
- Example:
const seasonNum = [1,2,3]; const seasons=[...,seasonNum[0]:{...}]
to add values computed by a variable
Optional Chaining
- Checking for Existence: Safely access nested object properties.
- Example:
console.log(serie?.seasons?.[0]?.episode)
safely checks for properties (without errors if one does not exist). - Example alternate:
console.log(serie?.seasons?.[6]?.released?.First);
for...of
Loop
- Iterating: Loop through the elements of an iterable.
- Example:
for(const item of arr){console.log(item)};
for...of
and entries
- Iterating over Arrays: Looping and getting index when iterating over an array
- Example:
for(const [i, el] of arr.entries){console.log(index,el)};
Sets
- Unique Values: Stores only unique values.
- No order: Elements have no specific order.
Maps
- Key-Value Pairs: Store key-value pairs where keys and values can be of any type.
- Creating: Constructing maps using
new Map()
. - Getting values: Getting values using
.get(key)
- Adding values: Adds values using
.set(key,value)
String Methods
- String Iterables: Access string elements individually.
- Useful Methods: Includes string methods like
.length
,.indexOf
,.slice
,.toLowerCase
,.trim
,.replaceAll
, and.repeat
.
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.