JS Arrays, Modern JavaScript & a little TypeScript Execute Program

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

Classes can be ______________ (have no name), and they can be _____________ (the class definition itself is used as an expression).

anonymous inline

A map's keys don't have to be strings. They can be ___________: arrays, objects, or even null and undefined.

anything

When defining a function with an explicit function type, we can only use the newer ______ _______________syntax:

arrow function

If the template literal ends in an interpolated value, like `age: ${age}`, JavaScript will insert one more empty string, '', _________________-

at the end

Interpolate in JavaScript with ______________

backticks

Sometimes we'll need to force a function to have a certain 'this'. We can do that using the ________ method.

bind

In JavaScript, any code with valid syntax will run. In TypeScript, code must have valid syntax and must ______________________. Only then will it run.

type check

When the compiler accepts a program's types, we say that that program ______________________-.

type checks

_________________ is when the types are used for type checking, then erased from the compiled output.

type erasure

What is a nifty JSON method to type check something?

typeof

The special case dealing with stringify and parse is ______________

undefined

When we call a JavaScript function with an argument missing, the corresponding parameter gets the value _______________.

undefined

const obj = {}; obj.defaultName; returns ____________

undefined

The following syntax uses a spread operator and created a _________ between two sets. const set1 = new Set([1, 2, 3]); const set2 = new Set([2, 3, 4]); const unionSet = new Set([...set1, ...set2]);

union

At each step, our replacer function can do three things: Return the value argument _______________, which won't change the stringified object. Return some _________ value, which will replace the original value in the stringified JSON. Return ____________-, which will remove the key from the stringified JSON.

unmodified other undefined

The short version is: const applies to the variable, not the __________ held by the variable.

value

the For of loop returns _____________

values

Is this TypeScript only or Javascript only? type MyNumberType = number;

TypeScript

we recommend that you always use _________ instead of var when declaring variables

let

True or false? In JavaScript, there is no syntax for multiple inheritance.

true

True or false? There's no rewind or restart method on iterators.

true

True or false? We can use iterators to iterator over infinite sets of data?

true

( () => 1 ).name;

''

What is the result of this code? JSON.stringify([1, undefined, 2]);

'[1,null,2]'

function five() { return 5; } five.name; What is returned here?

'five'

const one = () => 1; one.name;

'one'

What does this code return? const abc = [true, true, true]; abc.indexOf(false);

-1

We call the iterator's ___________ method repeatedly, looking at .value each time.

.next()

This is the correct syntax for symbols and calling them. Notice the hard brackets in ________ places const nameSymbol = Symbol('name'); const user = {[nameSymbol]: 'Amir'}; user[nameSymbol];

2

What is the result of this code? let sum: number = 1 + 1; sum;

2

the map itself is an iterable of ________________

2-element arrays

If we define an iterator that finds all of the prime numbers & then use const [p1, p2, p3, p4, p5] = primeNumbers(); [p1, p2, p3, p4, p5]; what will happen?

5 prime numbers

const arr = ['a', 'b', 'c']; arr.six = 6; arr['six']; What does the last line return?

6

true or false? Anonymous functions only get a name if they're assigned directly to a variable

true

We can turn a map into an array with ________________ if we have stored a map in the const mapObject

Array.from(mapObject)

True or False? Return is implicit in Javascript.

False

When extracting the keys for numbers and stringed numbers Non-numeric string keys come _________ number keys, in the order that they were inserted into the object.

after

Does JS throw an error when you forget to include an argument for a parameter?

No

_____________-It is the intentional absence of the value. It is one of the primitive values of JavaScript

Null

The original isNaN function was a mistake, and _____________________ should be preferred in all circumstances.

Number.isNaN

_____ contain only unique values. If we .add a value that already exists in the set, nothing happens; the set is unchanged.

Sets

____________- with objects means "include all of that object's properties in this object".

Spreading

We get an iterator by calling someIterableObject[________________]().

Symbol.iterator

To the object, the function name is just another _________!

key

_______________It means the value does not exist in the compiler. It is the global object.

Undefined

A JavaScript object's property __________ can be strings, numbers, or symbols.

keys

The for in loop returns _________

keys

What are the keys for this array in JS? Object.keys(['a','b','c'])

['0','1','2']

What will this code return? const arr1 = ['a', 'b']; arr1.five = 5; Object.keys(arr1);

['0','1','five']

What does this code return? Object.keys({2: 'two', b: 'b', 1: 'one', a: 'a'});

['1', '2', 'b', 'a']

What will this code return? const letters = ['a', 'b', 'c']; const [a, b, c, d='dee', e] = letters; [d, e];

['dee', undefined]

What will this code produce? const notAnIterable = 5; Array.from(notAnIterable);

[]

JSON can't represent ___________ objects.

circular

Inside of a static method or accessor, this refers to the _________ itself.

class

The _______________ can be a browser, an iOS device, etc.

client

The compiler forces us to use types correctly. If we use them incorrectly, it's a type error and the program won't ___________.

compile

.flat(Infinity) this flattens the array ___________

completely

We use [square brackets] when we want a ______________ property name. Ex. const key = 'name'; const {[key]: value} = {name: 'Amir'}; value;

computed

The _________ keyword doesn't stop us from mutating (changing) the value held by the variable. For example, we can mutate a const array by calling its push method.

const

What keyword can we use when we want to assign a variable name that we don't want to change?

const

How would you extract only the name of Betty's Car using destructuring? const user = { name: 'Betty', cat: { name: 'Keanu', age: 2, }, };

const {cat: {name}} = user;

Any value can be used as a ___________. For example, we can use an object as a default value.

default

Elements can be deleted from a set with the .___________ method. And the entire set can be cleared with .__________.

delete clear

Assignments with let, const, and the legacy var syntax can all use ________________________. (breaking apart arrays)

destructuring

The find method returns the ____________ itself

element

This code: const user = {name: 'Amir', age: 36} delete user would result in an __________

error

What will this code produce? const notAnIterable = 5; for (const x of notAnIterable) { }

error

What would be the result of the following code? const user = { name of the user() { return 'Amir' } } user.name()

error

______________________ are never allowed in types (ex. 1 + 1 or true || false)

expressions

JavaScript classes can __________ (inherit from) other classes by declaring class MySubclass extends MySuperclass

extend

The some method always returns ________ for an empty array.

false

instantiate() instanceof Dog; returns ____________

false

what would this code return? class Cat { } true instanceof Cat;

false

push returns the array's ____________, including the newly-pushed element.

length

With the keyword _______, a variable defined inside the if isn't visible outside the if

let

Always user ________ after calling new Array(someSize). to avoid empty slots.

fill

The _________- method fills an array with a given value. Any existing values will be overwritten by that value.

fill

If we immediately assign an anonymous function to a variable, that variable's name will become the _______________ name. (Functions created like this are still called "anonymous")

function's

Internally, JavaScript classes are just ______________.

functions

With hooks, the classes disappear and we just write ___________.

functions

Below is a _______________ function function* numbers() { yield 1; yield 2; yield 3; }

generator

The for _____ loop loops over the indices

in

When TypeScript determines the type for us without us explicitly writing it We call this type _______________, and we say that TypeScript infers types.

inference

If we define an iterator that finds all of the prime numbers & then use const [first, ...rest] = primeNumbers() what will happen?

infinite loop

We can't define a class ___________ another class. That causes an error, whether we use the class or not.

inside

A circular object is an object that references ___________

itself

Symbols help us to enforce conceptual separation in our systems by distinguishing data from ____________.

metadata

The important thing to know is that the replacer function exists, and that the replacer gets a chance to ____________ every part of the object as it's stringified.

modify

What is the "hidden" property of this function that we can call? function five() { return 5; } five.________; (it will return 'five')

name

If we have two key value pairs in a map and call Array.from(map) the result will be a _________ array

nested

Does the forEach loop return hidden or surprise array properties?

no

SHOULD you store 'surprise' elements on arrays in JavaScript?

no

let sum: number = 1 + 1; sum; In the code above we are assigning the result sum to the type ___________

number

What does this code return? typeOf [];

object

What does this code return? typeOf {};

object

For for _____ loop loops over the values

of

.keys & .values preserve ____________

order

An object's keys will be in the ___________ that they were defined in the object.

order

The function remembers its ___________ name, even if it's assigned to a different variable.

original

The ____________ method turns a JSON string back into an object.

parse

The Map constructor fetches each of the entries from the iterator one at a time. But remember that a generator never builds a full list of its contents. Instead, its iterator gives us one value via yield, then ______________ the generator function, waiting for us to request the next value. At any given time, only one of the values actually exists in memory.

pauses

Ultimately, the accessor is just another ____________ on the instance object.

property

The second argument in the JSON.stringify method is called the _________

replacer

The get and set keywords are ____________ when creating getters and setters.

required

const letters = ['a', 'b', 'c', 'd']; a) const [a, b, c] = letters; b) const a = letters[0], b = letters[1], c = letters[2]; A & B return the ___________ thing

same

Classes inside function have access to variables that are in ___________ within that function.

scope

In the following code, the toJSON key is telling the user object how it should be _________________- when the JSON.parse method is invoked on it. const user = { name: 'Amir', toJSON: () => 'This is Amir!' };

serialized

The server is whatever ___________ the data to the client.

serves

Methods defined inside of an object literal are called "______________- methods".

shorthand

This is an example of a ______________ method because it defines a method inside of an object literal const user = { name() { return 'Amir'; } }; user.name();

shorthand

const user = { name() { return 'Amir'; } }; user.name(); The above code is an example of a _____________ method

shorthand

Skipping indexes like this is called "_____________ array destructuring".

sparse

Set is a built in JS class that we can use to more efficiently check if a collection includes a ___________- element.

specific

Methods defined on the classes themselves are called ______________________________

static methods

If we try to use any other value as a key, that value is automatically converted into a __________-.

string

If you want to use punctuation you must use ____________________________

string keyed methods

const user = { 'name of the ~user~'() { return 'Betty'; } }; user['name of the ~user~'](); In the above code this method definition syntax is called __________- __________- __________ because we're using the normal JavaScript string syntax to define the method's name

string keyed methods

The ___________ method turns a JavaScript object or value into a JSON string. By default, it will pack the JSON tightly

stringify

sort converts the array's elements to ___________--, then compares them. Because it compares strings, it inherits the comparison problem above.

strings

If the subclass has a constructor, it has to call _____________() in its constructor before accessing any this properties.

super

The keyword __________ refers to the object that a function belongs to.

this

'3' > '10'

true

Order matters when setting object keys. When defining an object literal, the last value assigned to a key _______.

wins

Can you store 'surprise' elements on arrays in JavaScript?

yes

What does this code return? function returnsItsArguments(strings, ...values) { return { strings: strings, values: values, }; } returnsItsArguments`one${2}`;

{strings: ['one',''], values: [2]}


Ensembles d'études connexes

Chapter 1- Legal environment of business

View Set

Chapter 04: Developing the Role of Manager

View Set

Chapter 24: Nursing Care of the Child With an Integumentary Disorder (and alteration in tissue integrity)

View Set

Neuroplasticity and its Effects on the Brain

View Set

Finance 2303 Exam 1-- Chapters 1-4

View Set

Accounting activities for chpt. #1-2

View Set