JS Arrays, Modern JavaScript & a little TypeScript Execute Program

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

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 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

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

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

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]}

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

const

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

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

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

True or False? Return is implicit in Javascript.

False

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

( () => 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

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

2

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

6

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

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

TypeScript

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

Undefined

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 will this code return? const letters = ['a', 'b', 'c']; const [a, b, c, d='dee', e] = letters; [d, e];

['dee', undefined]

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

anonymous inline

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

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

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

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

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

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

key

The for in loop returns _________

keys

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

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

let

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 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

'3' > '10'

true

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

true

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

true

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

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


Kaugnay na mga set ng pag-aaral

Chapter 2 - Sets and Venn diagrams

View Set

RPA 2 - Ch. 3 Keogh & Small Employer Plans

View Set

Normal Distributions and Z-Score

View Set

Floral; Chapter 19; History of Floral Design

View Set

Blood, Toil, Tears and Sweat !!!!ANSWER KEY!!!!

View Set

Chapter 27 - Lower Respiratory Problems

View Set

Chapter 6: Sexuality and Society

View Set