Week 3

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

Getters and setters

A class method declaration preceded by the get keyword defines a getter method for a property. A class method declaration preceded by the set keyword defines a setter method for a property. Defining either a getter or setter method named X, adds a property named X to each class instance.

object literal

(also called an object initializer) is a comma-separated list of property name and value pairs.

JavaScript imposes the following rules for identifiers:

*An identifier can be any combination of letters, digits, underscores, or $. *An identifier may not start with a digit. *An identifier may not be a reserved word like let, function, or while.

What is the final value of numItems? bonus = 15; numItems = 44; if (bonus < 12) { numItems = numItems + 3; } else { numItems = numItems + 6; } numItems = numItems + 1;

51

What is output to the console? function multiplyNumbers(x, y) { answer = x * y; return answer; } var z = multiplyNumbers(2, 3); console.log(answer);

6

What is output to the console? function addNumber(x) { sum += x; } let sum = 0; addNumber(2); addNumber(5); console.log(sum);

7

points = 6; points++;

7

If window is the global object, what is the value of window.result after running the following code? function subtractNumbers(x, y) { result = x - y; } var a = subtractNumbers(7, 6); var b = subtractNumbers(11, 3); var c = subtractNumbers(9, 1);

8

What is points? points = 2; points *= 3 + 1;

8

points = 10; points--;

9

What is numBoxes at the end of each code segment? numApples = 2; numOranges = 5; numBoxes = 0; if (numApples % 2 != 0) { numBoxes = 1; } else { if (numApples + numOranges > 10) { numBoxes = 2; } else { numBoxes = 99; } }

99

class

A JavaScript class is a special function, called a constructor function, that defines properties and methods from which an object may inherit.

scope

A JavaScript variable's scope is the context in which the variable can be accessed.

Classes in EcmaScript 6

A class is declared by using the class keyword followed by a class name. The class is implemented by declaring methods within braces. Each method declaration is similar to a function declaration, but without the function keyword. The method name constructor() is reserved for the class constructor.

accessor property

An accessor property is an object property that has a getter or a setter or both.

argument

An argument is a value provided to a function's parameter during a function call.

arrow function

An arrow function is an anonymous function that uses an arrow => to create a compact function.

prompt()

The prompt() function prompts the user with a dialog box that allows the user to type a single line of text and press OK or Cancel.

this

The this keyword refers to the current object and is used to access properties inside the class.

A class can have both static and non-static methods.

True

A method may be defined inside or outside an object literal.

True

At the end of each loop iteration, a block scope object is removed from the front of the current scope chain.

True

At the start of each loop iteration, a new block scope object is prepended to the current scope chain.

True

Indicate if the if statement's condition evaluates to true or false. if (" ")

True

Indicate if the if statement's condition evaluates to true or false. if ("false")

True

Indicate if the if statement's condition evaluates to true or false. if (999)

True

Indicate if the if statement's condition evaluates to true or false. if (myArray)

True

The variable result is assigned 4. let square = function(num) { return num * num; } let result = square(2);

True

lowerCaseLetters = "abc"; upperCaseLetters = "ABC"; if (lowerCaseLetters > upperCaseLetters) { length++; }

True

score = 2; if (score = "50") { score = 100; }

True

score = 2; if (score == "2") { score = 10; }

True

status = "10"; if (status > 5) { length = 0; }

True

status = "good"; if (status > "bad") { bonus += 2; }

True

String concatenation

appends one string after the end of another string, forming a single string. Ex: "back" + "pack" is "backpack".

assignment

assigns a variable with a value, like score = 2. A variable may also be assigned a value on the same line when the variable is declared, which is called initializing the variable. Ex: let maxValue = 5; initializes maxValue to 5.

What is the data type of x? y = false; x = y;

boolean

identifier

name created for an item like a variable is called an identifier.

variable

named container that stores a value in memory.

After calling functions f1() and f2() in the code below, which variable(s) has/have global scope? function f1() { let x = 100; } function f2() { var y = 200; }

neither

constant

nitialized variable whose value cannot change. A JavaScript constant is declared with the const keyword. Ex: const slicesPerPizza = 8;

Which scripts have strict errors? "use strict"; function zig() { function zag() { let x = 1; } }

no error

Which scripts have strict errors? "use strict"; let p = { x: 5, x: 10};

no error

Which scripts have strict errors? "use strict"; let z; if (z > 0) { console.log("true"); }

no error

Which scripts have strict errors? function test(x) { "use strict"; let x = 1; }

no error

Which scripts have strict errors? x = 5; function test() { "use strict"; let y = 1; } Error No error

no error

Write a condition that executes the do-while loop as long as the user enters a negative number. let num; do { num = prompt("Enter a negative number:"); } while (______);

num < 0

Which code segment contains an error?

numLives = 9; let numLives;

What is the data type of population? let population = 650000;

number

The statement Y = 42; will _____.

replace Y's value of 99 with 42 in the second scope object

scope object

scope object: An object that stores a collection of variable names and corresponding values. Ex: Whenever a function with local variables is executed, the JavaScript runtime creates a scope object that stores the function's local variables.

JavaScript supports ______ inheritance, meaning a child class may only inherit from a single parent class.

single

What is boardType after the following statements? year = 1985; boardType = year >= 2015 ? "hoverboard" : "skateboard";

skateboard

variable declaration

statement that declares a new variable with the keyword let followed by the variable name. Ex: let score declares a variable named score.

parseInt() and parseFloat()

the JavaScript functions parseInt() and parseFloat() convert strings into numbers. Ex: parseInt("5") + 2 = 5 + 2 = 7, and parseFloat("2.4") + 6 = 2.4 + 6 = 8.4.

current execution context (running execution context)

the execution context at the top of the execution stack. The current scope chain is the scope chain of the current execution context.

prototype

the prototype object contains properties that an associated object inherits when the associated object is created.

while loop

the while loop is a looping structure that checks if the loop's condition is true before executing the loop body, repeating until the condition is false. The loop body is the statements that a loop repeatedly executes.

What is the data type of z? let z;

undefined

What is output to the console? function sayHello(name, greeting) { console.log(greeting + ", " + name + "!"); } sayHello("Maria");

undefined, Maria!

arithmetic operator

used in an expression to perform an arithmetic computation. Ex: The arithmetic operator for addition is +.

global scope

variable declared outside a function has global scope, and all functions have access to a global variable.

Other object map operations:

*Get number of elements. The Object.keys() method returns an array of an object's property names. The array's length property returns the number of elements in the object map. *Check for key. The in operator returns true if an object contains the given property and returns false otherwise. *Remove element. The delete operator removes a key/property from a map or object.

Refer to the switch statement below. switch (item) { case "apple": case "orange": fruits++; break; case "milk": drinks++; case "cheese": dairy++; break; case "beef": case "chicken": meat++; break; default: other++; }

*If item is "beef", what variables are incremented? ==> Meat only *If item is "milk", what variables are incremented? ==> Drinks and dairy *If item is "Apple", what variable is incremented? ==> Other

Refer to the object map below. let students = { 123: { name: "Tiara", gpa: 3.3 }, 444: { name: "Lee", gpa: 2.0 }, 987: { name: "Braden", gpa: 3.1 } };

*Remove Lee from students. ==>delete students[444]; *Assuming students has three elements before the code executes, what number is output to the console? delete students["Braden"]; console.log(Object.keys(students).length); ==>3 *What is missing to check if student ID 888 is in students? ==>if (888 in students) { console.log("Hello, " + students[888].name); } *What is output to the console? for (let id in students) { delete students[id]; } if (123 in students) { console.log("yes"); } else { console.log("no"); } ==>no

Refer to the code below. function multiplyNumbers(x, y) { var answer = x * y; return answer; } var z = multiplyNumbers(2, 3); console.log(answer);

*The answer variable has local scope. *The z variable has global scope. *The console.log(answer); line throws a referenced error

Common methods and properties of the Map object include:

*The set(key, value) method sets a key/value pair. If the key is new, a new element is added to the map. If the key already exists, the new value replaces the existing value. *The get(key) method gets a key's associated value. *The has(key) method returns true if a map contains a key, false otherwise. *The delete(key) method removes a map element. *The size property is the number of elements in the map.

const strings = ["one", "two words", "three", "four five"]; function getSingleWords(stringArray) { const noSpace = function(element) { return element.indexOf(" ") === -1; }; return stringArray.filter(noSpace); } function getStartingWith(stringArray, startString) { function startsWith(string) { return string.indexOf(startString) === 0; } return stringArray.filter(startsWith); }

*What does getSingleWords(strings); return? ==> ["one", "three"] *Which inner function uses a variable from the outer function? ==>startsWith() *What does getStartingWith(strings, "t"); return? ==> ["two words", "three"]

Refer to the code below. function changeMovie(movie) { movie.title = "The Avengers"; movie.released = 2012; movie = { title: "Avengers: Endgame", released: 2019 }; } let avengersMovie = { title: "Avengers: Infinity War", released: 2018 };

*What is output to the console? changeMovie(avengersMovie); console.log(avengersMovie.title); ==>The Avengers *What is output to the console? let myMovie = avengersMovie; myMovie.title = "Avengers: Age of Ultron"; console.log(avengersMovie.title); ==>Avengers: Age of Ultron

Refer to the map below. let contacts = new Map(); contacts.set("Rosa", { phone: "303-555-4321", email: "[email protected]" }); contacts.set("Dave", { phone: "501-533-9988", email: "[email protected]" }); contacts.set("Li", { phone: "213-511-6758", email: "[email protected]" });

*What is output to the console? console.log(contacts.size); ==>3 *What is output to the console? contacts.set("Li", { phone: "213-444-6758", email: "[email protected]" }); console.log(contacts.size); ==>3 *What is output to the console? contacts.delete("Li"); console.log(contacts.size); ==>2 *Which expression loops through the contacts map to output all names and phone numbers? for (______) { console.log(name + ": " + contact.phone); } ==>let [name, contacts] of contacts

Refer to the object map below. let contacts = { Rosa: { phone: "303-555-4321", email: "[email protected]" }, Dave: { phone: "501-533-9988", email: "[email protected]" }, Li: { phone: "213-511-6758", email: "[email protected]" } };

*What outputs Dave's email address? ==>console.log(contacts["Dave"].email); *What assigns a Twitter username to Rosa? ==>contacts["Rosa"].twitter= "@rosaLuvsCats"; *What adds John to the contacts map? ==>contacts["John"]= { phone: "111-2222", email: "[email protected]" }; *Which expression loops through the contacts map to output all names and phone numbers? ==>for (name in contacts) { console.log(name + ": " + contacts[name].phone); }

Refer to the book object below. let book = { title: "Hatching Twitter", published: 2013, keywords: ["origins", "betrayal", "social media"], author: { firstName: "Nick", lastName: "Bilton" } };

*Which statement changes the published year to 2014? book.published = 2014; *Which statement adds a new property called "isbn" with the value "1591846013"? book.isbn = "1591846013"; *What statement replaces "Nick" with "Jack"? book.author.firstName = "Jack"; *What is missing from the code below to remove "social media" from the book's keywords? The array method pop() removes the last element from an array. book.keywords.pop();

What is secretCode at the end of each code segment? Type "quotes" around strings. If not a number, type Nan

*secretCode = 10 + "ten"; ==> "10ten" *secretCode = "3" / "6"; ==> 0.5 *secretCode = "3" + 5 * 2; ==>310 *secretCode = parseFloat("3.2") + parseInt("2.7"); ==> 5.2 *secretCode = 3 + parseInt("pig"); ==> NaN *// true = 1, false = 0 secretCode = 2 + isNaN("oink") + isNaN("5"); ==>3

function expression

. A function expression is identical to a function declaration, except the function name may be omitted. A function without a name is called an anonymous function. Anonymous functions are often used with arrays and event handlers

What compound assignment operator makes points become 2.5? points = 5; points ___ 2;

/=

What does the following code log to the console? function getFunction() { var functionToReturn = null; var i = 0; while (i < 5) { const saved_i = i; if (i === 0) { functionToReturn = function() { console.log(saved_i); }; } i++; } return functionToReturn; } const theFunction = getFunction(); theFunction();

0

What is points? points = 4; points %= 2;

0

What is decision at the end of each code segment? homeTeam = 2; visitingTeam = 5; if (homeTeam > 10 || visitingTeam > 0) { decision = 1; } else { decision = 0; }

1

What is decision at the end of each code segment? homeTeam = 2; visitingTeam = 5; if (!(homeTeam > 10 && visitingTeam > 0)) { decision = 1; } else { decision = 0; }

1

What is decision at the end of each code segment? homeTeam = 2; visitingTeam = 5; if (homeTeam > 10 || (visitingTeam != 2 && visitingTeam > 0)) { decision = 1; } else { ecision = 0; }

1

What is numBoxes at the end of each code segment? numApples = 2; numOranges = 5; numBoxes = 0; if (numApples > 0) { if (numOranges > 10) { numBoxes = 4; } numBoxes++; } else { numBoxes = 99; }

1

What is the final value of numItems? bonus = 0; numItems = 1; if (bonus > 10) { numItems = numItems + 3; }

1

What is the final value of numItems? bonus = 5; if (bonus < 12) { numItems = 100; } else { numItems = 200; }

100

What are the first and last numbers output by the code segment? let c = 100; while (c > 0) { console.log(c); c -= 10; }

100 and 10

points = 3 + 5 * 2;

13

What is output to the console? console.log(findSmallest(5, 2)); function findSmallest(x, y) { if (x < y) { return x; } else { return y; } }

2

function factorial(num) { let result = 1; for (let count = 1; count <= num; count++) { result *= count; } return result; } let answer = factorial(8 - factorial(3)); console.log(answer);

2

points = 4; points = (3 + points) % 5;

2

What numbers are output by the code segment? for (x = 1; x <= 3; x++) { for (y = 2; y <= 4; y++) { console.log(y); } }

2,3,4,2,3,4,2,3,4

What is the final value of numItems? bonus = 12; if (bonus < 12) { numItems = 100; } else { numItems = 200; }

200

What is the final value of numItems? bonus = 5; if (bonus < 12) { bonus = bonus + 2; numItems = 3 * bonus; } else { numItems = bonus + 10; }

21

What is numBoxes at the end of each code segment? produce = "carrots"; if (produce == "apples") { numBoxes = 1; } else if (produce == "bananas") { numBoxes = 2; } else if (produce == "carrots") { numBoxes = 3; } else { numBoxes = 4; }

3

What is priority after the following statements? attempt = 4; priority = 2; attempt > 3 ? priority++ : priority--;

3

What does the following code log to the console? function getFunction() { var functionToReturn = null; var i = 0; while (i < 5) { var saved_i = i; if (i === 0) { functionToReturn = function() { console.log(saved_i); }; } i++; } return functionToReturn; } const theFunction = getFunction(); theFunction();

4

What is the final value of numItems? bonus = 19; numItems = 1; f (bonus > 10) { numItems = numItems + 3; }

4

scale = 5; points = 3 ** 2 * scale;

45

What does the following code log to the console? function getFunction() { var functionToReturn = null; var i = 0; while (i < 5) { if (i === 0) { functionToReturn = function() { console.log(i); }; } i++; } return functionToReturn; } const theFunction = getFunction(); theFunction();

5

What is the last number output to the console? let c = 10; do { console.log(c); c--; } while (c >= 5);

5

What is the last number output to the console? let x = 1; do { let y = 0; do { console.log(x + y); y++; } while (y < 3); x++; } while (x < 4);

5

What numbers are output by the code segment? for (c = 5; c < 10; c += 2) { console.log(c); }

5,7,9

closure

A closure is a combination of a function's code and a reference to a scope chain. When a JavaScript function is declared, a closure is created that includes the function's code and a reference to the current scope chain. Closures are what allow an inner function to access the outer function's variables.

closure

A closure is a special object that is automatically created and maintains a function's local variables and values after the function has returned.

javascript comments

A comment is any text intended for humans that is ignored by the JavaScript interpreter. JavaScript uses the // and /* */ operators to produce comments in code.

comparison operator

A comparison operator compares two operands and evaluates to a Boolean value, meaning either true or false.

constructor function

A constructor function is a function that initializes a new object when an object is instantiated with the new operator.

falsy

A falsy value is a non-Boolean value that evaluates to false in a Boolean context. Ex: if (null) evaluates to false because null is a falsy value.

for loop

A for loop executes the initialization expression, evaluates the loop's condition, and executes the loop body if the condition is true. After the loop body executes, the final expression is evaluated, and the loop condition is checked to determine if the loop should execute again.

function

A function is a named group of statements. JavaScript functions are declared with the function keyword followed by the function name and parameter list in parentheses ()

return

A function may return a single value using a return statement. A function that is missing a return statement returns undefined.

getter

A getter is a function that is called when an object's property is retrieved. Syntax to define a getter: get property() { return someValue; }.

map or associative array

A map or associative array is a data structure that maps keys to values.

parameter

A parameter is a variable that supplies the function with input. The function's statements are enclosed in braces {}.

JavaScript data types can be divided into two categories: primitives and references.

A primitive is data that is not an object and includes no methods. Primitive types include: boolean, number, string, null, and undefined. A reference is a logical memory address. Only objects are reference types.

private property

A private property is a property that is only accessible to object methods but is not accessible from outside the class. Private properties may be simulated in JavaScript by creating local variables in a constructor function with getters and setters to get and set the properties.

scope chain

A scope chain is a linked list of scope objects used by the JavaScript runtime to store and lookup variable values when executing code. When a variable is needed, a search begins at the scope object at the beginning of the scope chain. If the variable is found, the corresponding value is used. Otherwise, the next object in the scope chain is searched. If the search reaches a null object at the end of the scope chain, the variable is not found and a ReferenceError is thrown.

setter

A setter is a function that is called when an object's property is set to a value. Syntax to define a setter: set property(value) { ... }.

A setter method _____.

A setter method takes exactly 1 parameter, which is the value to set.

static method

A static method is a method that can be called without creating an instance of the class. A static method is declared with the static keyword preceding the method name. The method is called with the syntax: ClassName.methodName(arguments).

switch statement

A switch statement compares an expression's value to several cases using strict equality (===) and executes the first matching case's statements. If no case matches, an optional default case's statements execute.

truthy

A truthy value is a non-Boolean value that evaluates to true in a Boolean context. Ex: if (18) evaluates to true because non-zero numbers are truthy values.

local scope

A variable declared inside a function has local scope, so only the function that defines the variable has access to the local variable

block scope

A variable declared inside a function with let has block scope: the variable is accessible only within the enclosing pair of braces.

function scope

A variable declared inside a function with var has function scope: the variable is accessible anywhere within the function, but not outside.

execution context

An execution context is an object that stores information needed to execute JavaScript code, and includes, but is not limited to: information about code execution state, such as the line of code being executed and the line to return to when a function completes, and a reference to a scope chain.

if statement

An if statement executes a group of statements if a condition is true. Braces { } surround the group of statements.

if-else statement

An if-else statement executes a block of statements if the statement's condition is true, and executes another block of statements if the condition is false.

infinite loop

An infinite loop is a loop that never stops executing. Ex: while (true); is an infinite loop because the loop's condition is never false.

inner function (nested function)

An inner function (nested function) is a function declared inside another function.

object

An object is an unordered collection of properties.

property

An object property is a name-value pair, where the name is a string and the value is any data type. Objects are often defined with an object literal.

Method

An object property may be assigned an anonymous function to create a method. Methods may access the object's properties using the keyword this, followed by a period, before the property name. Ex: this.someProperty.

operand

An operand is the value or values that an operand works on, like the number 2 or variable x.

outer function

An outer function is a function containing an inner function. An inner function can access variables declared in the outer function.

Element

Each key/value pair in a map is called an element. JavaScript objects can be used as maps, in which the key is the object property and the value is the property's value.

Indicate if the statements contain an error or not. /* a is assigned 2 a = 2;

Error, /* begins a comment, but */, which ends the comment, is missing.

Indicate if the statements contain an error or not. 3.12 = pi;

Error, A number may not be assigned a variable. pi = 3.12; is a proper assignment statement.

All browsers must use the same JavaScript engine

False

For a loop that executes N times, any variable declared inside a loop's body is stored in N distinct block scope objects.

False

Indicate if the if statement's condition evaluates to true or false. if ("")

False

Indicate if the if statement's condition evaluates to true or false. if (0)

False

Indicate if the if statement's condition evaluates to true or false. if (undefined)

False

JavaScript is only used for programs that run in a web browser. True False

False

Non-static methods can also be called with the ClassName.methodName(arguments) syntax.

False

The scope chain with more than 2 scope objects implies that at least 1 function call was made

False

The variable result is assigned 9. let result = square(3); let square = function(num) { return num * num; }

False

The variable result is assigned 9. let square = function(num) { return num * num; } let result = square;

False

score = 2; if (score === "2") { score = 10; }

False

status = "charge"; if (status <= "chance") { bonus += 2; }

False

ECMAScript and JavaScript are the same thing. True False

False, ECMAScript is the standard upon which JavaScript is based. The standard is called ECMAScript, but the implementation is called JavaScript.

hat is output to the console? sayHello("Sam"); sayHello("Juan", "Hola"); function sayHello(name, greeting = "Hello") { console.log(greeting + ", " + name); }

Hello, Sam Hello, Juan

What is output to the console? console.log(sayHello("Sam")); function sayHello(name) { console.log("Hello, " + name + "!"); }

Hello, Sam! undefined

nested

If and else block statements can include any valid statements, including another if or if-else statement. An if or if-else statement that appears inside another if or if-else statement is called a nested statement.

Inheritance

Inheritance creates a new child class that adopts properties of a parent class. Ex: A Student class (child) may inherit from a Person class (parent), so a Student class has the same properties of a Person and may add even more properties.

Array filtering

Inner functions are commonly used for array filtering. An Array object's filter() method takes a filter function as an argument, calls the filter function for each array element, and returns a new array consisting only of elements for which the filter function returns true.

function call

Invoking a function's name, known as a function call, causes the function's statements to execute.

dynamic typing

JavaScript uses dynamic typing, which determines a variable's type at run-time. Every variable has a data type

NaN

JavaScript value that means Not a Number. Ex: parseInt("dog") is NaN. The JavaScript function isNaN() returns true if the argument is not a number, false otherwise. Ex: isNaN("dog") is true.

ECMAScript

JavaScript was standardized by Ecma International in 1997 and called ECMAScript. JavaScript is an implementation of the ECMAScript specification.

complex condition

Multiple && and || conditions may be combined into a single complex condition. Ex: (1 < 2 && 2 < 3 || 3 < 4). Complex conditions are evaluated from left to right, but && has higher precedence than ||, so && is evaluated before ||.

Indicate if the statements contain an error or not. x = 10; let y = 20;

No error

Strict mode

Strict mode makes a JavaScript interpreter apply a set of restrictive syntax rules to JavaScript code. To enable strict mode for an entire script, the statement "use strict" must be placed before any other statements.

Map object

The Map object is a newer alternative to using objects for storing key/value pairs.

break statement

The break statement stops executing a case's statements and causes the statement immediately following the switch statement to execute. Omitting the break statement causes the next case's statements to execute, even though the case does not match.

conditional operator (or ternary operator)

The conditional operator (or ternary operator) has three operands separated by a question mark (?) and colon (:). If the condition evaluates to true, then the value of expression1 is returned, otherwise the value of expression2 is returned.

do-while loop

The do-while loop executes the loop body before checking the loop's condition to determine if the loop should execute again, repeating until the condition is false.

else if

The else-if statement is an alternative to nested if-else statements that produces an easier-to-read list of statement blocks.

Inheritance

The extends keyword allows one class to inherit from another. In the inheriting class' constructor, calling the super() function calls the parent class' constructor. super() must be called before using the this keyword in the inheriting class' constructor.

for-in loop

The for-in loop is ideal for looping through an object map. The for-in loop iterates over an object's properties in arbitrary order.

identity operator ===

The identity operator === performs strict equality. Two operands are strictly equal if the operands' data types and values are equal. Ex: 3 === 3 is true because both operands are numbers and the same value, but "3" === 3 is false because "3" is a string, and 3 is a number.

What is the value of c when the loop terminates? let c = 10; while (c <= 20); { console.log(c); c += 5; }

The loop never terminates (semilcolon)

non-identity operator !==

The non-identity operator !== is the opposite of the identity operator. Ex:

Unicode

Unicode is a computing industry standard that assigns a unique number to characters in over one hundred different languages, including multiple symbol sets and emoji. The Unicode numbers for capital A-Z range from 65 to 90, and lowercase a-z range from 97 to 122.

var

a variable can be declared with the var keyword. Ex: var x = 6; declares the variable x with an initial value of 6.

the global object

an object that stores certain global variables, functions, and other properties. When running JavaScript code in a web browser, global variables are usually assigned as properties to the global window object. Therefore, a global variable called test is accessible as window.test.

In the code below, which variable(s) is/are in scope on the blank line? function OneToTen() { let a = 1; for (var i = a; i <= 10; i++) { console.log(i); _____ } }

both a and i

What condition makes the loop output the even numbers 2 through 20? let c = 2; while (_____) { console.log(c); c += 2; }

c <= 20

What condition causes the for loop to output the numbers 100 down to 50, inclusively? for (c = 100; ______; c--) { console.log(c); }

c >= 50

If a getter method for property X is added to a class, a setter method for X _____.

can be added but is not required

expression

combination of items like variables, numbers, operators, and parentheses, that evaluates to a value like 2 * (x + 1).

compound assignment operator

combines an assignment statement with an arithmetic operation

Which function call displays the numbers 5, 4, 3, 2, 1. function countDown(firstNum) { for (let count = firstNum; count > 0; count--) { console.log(count); } }

countDown(5);

Choose a better name for the function test. function test(x, y) { if (x > y) { console.log(x); } else { console.log(y); } }

displaylargest

Which loop always executes the loop body at least once?

do-while

Which scripts have strict errors? "use strict"; function test(a, b, a) { return a - b; }

error

Which scripts have strict errors? "use strict"; if (true) { function test() { let x = 1; } }

error

Which scripts have strict errors? "use strict"; let p = { get x() { return 0; } }; p.x = 1;

error

Which scripts have strict errors? "use strict"; let x = 2 + 04 + 8;

error

Which scripts have strict errors? "use strict"; x = 10;

error

Which scripts have strict errors? function test() { "use strict"; let interface = 1; }

error

interpreter

executes programming statements without first compiling the statements into machine language. Modern JavaScript interpreters (also called JavaScript engines) use just-in-time (JIT) compilation to compile the JavaScript code at execution time into another format that can be executed quickly.

Suppose obj is an instance of a class with a property named value, which has both a getter and setter. The statement below calls the _____. obj.value += 10;

getter first then setter

What is syntactically wrong with the following code? name = 'Danny O'Sullivan';

if single quotes are used as string delimiters, then single quotation marks inside the string must be escaped with a backslash character. Ex: 'Danny O\'Sullivan'. Alternatively, double quotes can be used as string delimiters. Ex: "Danny O'Sullivan"

On the blank line in the code below, variable k _____. function SumOfSquares() { let sum = 0; for (let i = 1; i < 5; i++) { let j = i * i; sum += j; var k = sum; } _____ }

is in scope and has a value of 30

Complete the code to assign lateStatus with "yep" if currTime is greater than 60, and "nope" otherwise.

lateStatus = currTime > 60 ? "yep" : "nope";

What is the correct way to call factorial() and output the factorial of 5? function factorial(num) { let result = 1; for (let count = 1; count <= num; count++) { result *= count; } return result; }

let answer = factorial(5); console.log(result);

Complete the arrow function.

let countCapitals = str=> { let count = 0; for (let i = 0; i < str.length; i++) { let ch = str.charAt(i); if (ch >= 'A' && ch <= 'Z') { count++; } } return count; }

onvert isEven() into an equivalent arrow function. function isEven(num) { return num % 2 === 0; }

let isEven = num =>num % 2 === 0;

Complete the arrow function.

let max =(a, b) => a > b ? a : b;

The statement console.log(X) will _____.

log 101 to the console

What is c when the loop terminates? let c = 10; while (c <= 20) console.log(c); c += 5;

loop never terminates (curly braces)

console.log()

which displays text or numbers in the console. The console is a location where text output is displayed. Web browsers have a console (accessible from the brower's development tools) that displays output from code the browser executes.

Complete the code to assign y with x if x is greater than 0, and -1 otherwise.

y = (x > 0) ? x : -1;


संबंधित स्टडी सेट्स

Asymmetric Encryption and it's Uses

View Set

BE 301 KU Exam 1 Multiple Choice

View Set

Microbiology: iClicker, Smartwork5, Quiz 3

View Set

Economics Chapter 8: The Price Level and Inflation

View Set

GC Practice Quiz Problems Ch. 7/8/9

View Set