ECMAScript6(ES6)

¡Supera tus tareas y exámenes ahora con Quizwiz!

What does the function in a promise contain?

an if statement with a condition and command to perform if the condition is met (resolve) and a command to perform if the condition is not met (reject)

Where is the only place a rest element works correctly?

as the last variable in the list

What punctuation is used to wrap the string in a template literal?

backticks (`)

What is the relationship of the term ECMAScript with JavaScript?

because of the widespread acceptance of the ECMAScript specification of JS, the two terms are interchangeable

How can you import more than one item from a file?

by adding them in the import statement like this: import { varname1, varname2 } from './filename.js';

How can the value at any index in an array be reached with destructuring?

by using commas to reach the desired index ( const [a, b,,, c] = [1, 2, 3, 4, 5, 6]

What is a common practice when naming constants?

use all uppercase letters, with words separated by an underscore

How do you work with nested objects when using destructuring assignment?

use same principles as otherwise but just with nested items (e.g. const { johnDoe: { age, email} } = user; or const { johnDoe: {age: userAge, email: userEmail } } = user;)

How is let used in a declaration?

let camper = 'James';

What is an example of other expressions that can be included in a template literal string literal?

${a + b}

In the array destructuring cosnt [a, b] = [1, 2, 3, 4, 5, 6]; what elements are assigned to a and b respectively?

1, 2

What elements would the rest parameter collect in the array destructuring const [a, b, ...arr] = [1, 2, 3, 4, 5, 7];

3, 4, 5, 7

What is the result of collecting the rest of the elements (outside an array destructuring) into a separate array similar to?

Array.prototype.slice( )

What is the relationship of ECMAScript to JavaScript?

ECMAScript is a standardized version of JavaScript with the goal of unifying the language's specifications and features

What is the most recent standardized version of ECMAScript?

ECMAScript or ES6

What does the spread operator allow?

allows us to expand arrays and other expressions in places where multiple parameters or elements are expected

What option does destructuring give for assigning a new variable name?

allows you to assign a new variable name when extracting values by putting the new name after a colon

use destructuring assignment to swap the values of a and b in let a = 8, b = 6; so that a receives the value stored in b, and b receives the value stored in a

[a, b] = [b, a];

What kind of function is a promise?

a constructor function

What is a template literal?

a special type of string that makes creating complex strings easier

What does the use of let control?

a variable with the same name can only be declared once

What is the limit on number of default values?

can add default values for as many parameters as you want

What do anonymous functions allow if there is no function body and only a return value?

can omit the keyword return as well as the brackets surrounding the function code

What does destructuring an array allow that is not possible with the spread operator?

can pick or choose which elements you want to assign to variables

How does ES6 allow for concise declarative functions?

can remove the "function" keyword and colon altogether when defining functions in objects

What is used in place of "var" to create a new object?

const

How would a rest parameter appear with an array destructuring to collect the rest of the elements in an array?

const [a, b, ...arr] = [1, 2, 3, 4, 5, 7];

What is an example of an array destructuring that assigns elements from an array to individual variables?

const [a, b] = [1, 2, 3, 4, 5, 6];

What is an example of a streamlined anonymous function?

const myFunc = ( ) => "value";

What is an example of two extractions of values from an object ("user") that a destructuring assignment could replace?

const name = user.name const age = user.age

What is an example of calling "new" to create a new object in ES6?

const objectname = new classname('argument');

How does the default parameter work in a function?

kicks in when the argument is not specified (undefined)

What is the syntax of a promise?

const varname = new Promise ((resolve, reject) => {});

What is a second way to export a variable or function without having to rewrite the code?

const varname... export { varname };

How would the items in the following object be given new variable names in a destructuring assignment: const user = { name: 'John Doe', age: 34 };

const { name: userName, age: userAge } = user

What is an example of a destructuring assignment used to extract two values from an object in a single statement?

const {name, age} = user;

What kind of value are const variables?

constant values

What is included after the first curly bracket in an ES6 class declaration of a new function?

constructor (i.e., constructor (functionParameter) )

What additional use does the export default syntax have?

creating a fallback value for a file or module

What do template literals allow?

creation of multi-line strings and use of string interpolation features to create strings

What does the "use strict" statement enable?

enables a mode which catches common coding mistakes and "unsafe" actions

What is one method for exporting a variable containing a function?

export const varname = (parameters) => { thefunctioncode; }

What is an example of export default syntax for a function called "add"?

export default function (x, y) { return x + y; }

What does ES6 allow to make sharing of code among JavaScript files easier?

exporting parts of a file for use in one or more other files, and importing the parts you need, where you need them

Where does result come from as used in the then method?

from the argument given to the resolve method

What is the syntax for a default value assigned to a parameter in a function?

function (parameter = "default");

What does a rest parameter look like?

function funcname(...args)

What is an anonymous function?

function used with a constant that doesn't have to be named because it's not going to be reused

How does the scope of a variable declared with let differ from that of a variable declared with var?

if declared within a for loop, it has local and not global scope

When is the export default syntax used?

if only one value is being exported from a file

Under what condition can the parentheses enclosing the argument in an arrow function be omitted?

if the arrow function has a single argument

What is an example of an if-statement inside a promise

if(condition here) { resolve("Promise was fulfilled"); } else { reject("Promise was rejected"); }

When is catch executed?

immediately after a promise's reject method is called

What is an example of importing all of a file's contents where the contents of a file named math_functions.js are imported into a file named "myMathModule" in the same directory?

import * as myMathModule from "./math_functions.js";

What syntax is used to import a default export?

import anyname from "./filename.js";

How do you import a file or module from a file to use in another file?

import { varname } from './filename.js';

When was ES6 released?

in 2015

How does object property shorthand work?

in a function that returns an object with properties, ES6 allows syntax that eliminates having to write out object: property (when object and property are the same???) and simply write the name (of both the object and property?) once, and it will be converted to object: property

Where is ECMAScript prevalent?

in all major browsers and JavaScript-runtimes

Where does error come from in the catch method?

it's the argument passed in to the reject method

How does a template literal work?

just drop the variable in a template string and wrap it with ${ }

What does the rest parameter allow to be applied on the parameters array?

map( ), filter( ) and reduce( )

What role do the parameters resolve and reject play in a promise?

methods to determine the outcome of the promise

What are setter functions meant to do?

modify the value of an object's private variable based on the value passed into the setter function

What is an example of using a function ("add") imported into a file named myMathModule?

myMathModule.add(2,3);

What is the syntax for catch?

myPromise.catch(error => { command });

What shortcut does ES6 offer for easily defining literals?

object property shorthand

What kind of mutability does the object or array assigned to a constant have?

objects assigned to a variable using const are still mutable

What does a getter do?

obtains values from an object

What does constant value mean?

once a variable is assigned with const, it cannot be reassigned (returns error)

What limit exists on the spread array?

only works in some context (can't just be called on its own)

What problem was the new keyword let introduced in ES6 to solve?

overwriting of variable declarations without throwing an error

What three states does a promise have?

pending, fulfilled, and rejected

What does the function Object.freeze do?

prevents data mutation of a constant object

How does a promise in JS work?

promise to carry out command is made; when task completes, promise either is fulfilled or fails to do so

What are getter functions meant to do?

return the value of an object's private variable to the user without the user directly accessing the private variable

What does the spread operator do?

returns an unpacked array within a function (i.e., it spreads the array)

What do you need to create in your HTML document in order to take advantage of ES6's method for easy exporting and importing of modules?

script tag of type "module"

What does a setter do?

sets a value of a property within an object

What is the syntax of the then method?

somePromise.then(result => { command });

What is destructuring assignment?

special syntax introduced in ES6 for neatly assigning values taken directly from an object

What is distinct about the string and the output in a template literal?

string and output are both multi-line

How is a promise constructed?

takes a function, as its argument, with two parameters: resolve and reject

What does ES6 "class" syntax replace in ES5?

the constructor function creation (i.e., var x = function(y))

What is catch?

the method used when your promise has been rejected

What do you need to use to create a promise?

the new keyword

Why is it not possible to pick or choose which elements you want to assign to variables with a spread operator?

the spread operator unpacks all contents of an array into a comma-separated list

What additional feature do variables declared using const have?

they are read-only

What happens if you declare a variable more than once using let?

throws an error

When can a then method be used?

to do something with the response that results from an asynchronous process (i.e. after a promise is fulfilled with resolve)

What is the rest parameter used for?

to help create more flexible functions

What is the convention regarding the name of a private variable in a getter or setter?

to precede the name of a private variable with an underscore (_)

What can export default not be used with?

var, let, or const

When are promises most useful?

when you have a process that takes an unknown amount of time in your code (i.e. something asynchronous), often a server request

What is another way besides let to declare a variable in ES6?

with the const keyword

How can you import all of a file's contents into the current file?

with the import * as syntax

What does arrow function syntax allow?

writing of anonymous function

What does the rest parameter allow?

you can create functions that take a variable number of arguments, which are stored in an array that can be accessed later from inside the function

In what way are arrow functions like regular functions?

you can pass arguments into an arrow function


Conjuntos de estudio relacionados

Reading 06 - The Behavioral Finance Perspective

View Set

Praxis II Physical Education (5091)

View Set

Chapter 6 - Maintaining System Startup and Services

View Set

20th Century Music History Test 3

View Set

Chapter 10 Section 4: The Members of Congress

View Set

Post Traumatic Stress Disorder (PTSD)- Final

View Set

CompTIA A+ Core 2 Lesson 8 Quiz - Managing Security Settings

View Set

Project Management Chapter 4 SB & Quiz

View Set

English Antigone Study Guide (know who said quotes)

View Set

Practice Test Assessment Performance

View Set