Module 2 - Variables, Operators, and Strings

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

False

It is okay to use numbers at the start of a variable name.

7

var num1 = 6; var num2 = 15; var myNum = num1 + (num2 / 2 - 0.5) % 3; 7 0 8.5 1 10

18

Given the JavaScript code below, what would be output to the console? var myNum = 17; myNum++; console.log(myNum); 18 17 16 19 15

var myNumber = 123; var myString = myNumber.toString();

In order to convert the variable myNumber into the data type string and assign it to a new variable called myString, use the following code: var myString = '123'; var myNumber = myString.convertTo(number); var myString = '123'; var myNumber = myString.typeof(number); var myNumber = 123; var myString = toString(myNumber); var myNumber = 123; var myString = myNumber.toString(); var myString = '123'; var myNumber = typeof(myString) = number;

var myString = '123'; var myNumber = Number(myString);

In order to convert the variable myString into the data type number and assign it to a new variable called myNumber, use the following code: var myString = '123'; var myNumber = toNumber(myString); var myString = '123'; var myNumber = myString.typeof(number); var myString = '123'; var myNumber = myString.toNumber(); var myString = '123'; var myNumber = Number(myString); var myString = '123'; var myNumber = number(myString);

var myPizza = "Cheese and Pepperoni Pizza"; var pepperoniPos = myPizza.indexOf('Pepperoni'); var topping = myPizza.slice(pepperoniPos, pepperoniPos + 9);

In order to extract the substring "Pepperoni" from the string "Cheese and Pepperoni Pizza" and assign it to a variable called topping, you would need which of the following blocks of code: var myPizza = "Cheese and Pepperoni Pizza"; var pepperoniPos = indexOf('Pepperoni').myPizza; var topping = myPizza.slice(pepperoniPos, pepperoniPos + 9); var myPizza = "Cheese and Pepperoni Pizza"; var pepperoniPos = myPizza.indexOf('Pepperoni'); var topping = myPizza.slice(pepperoniPos, pepperoniPos + 9); var myPizza = "Cheese and Pepperoni Pizza"; var pepperoniPos = myPizza.indexOf('P'); var topping = myPizza.slice(pepperoniPos, pepperoniPos + 9); var myPizza = "Cheese and Pepperoni Pizza"; var pepperoniPos = myPizza.indexOf('Pepperoni'); var topping = myPizza.slice(pepperoniPos, pepperoniPos + 8); var myPizza = "Cheese and Pepperoni Pizza"; var pepperoniPos = myPizza.indexOf('Pepperoni'); var topping

var myString = 'JavaScript'; var letterS = myString[4];

In order to return the letter "S" from the string "JavaScript," you'd need to use the following code: var myString = 'JavaScript'; var letterS = myString[4]; var myString = 'JavaScript'; var letterS = myString[5]; var myString = 'JavaScript'; var letterS = myString['S']; var myString = 'JavaScript'; var letterS = myString(4); var myString = 'JavaScript'; var letterS = myString[5thChar];

number

JavaScript has only one data type for numbers, and that is __________.

var myCar = 'hatchback'; -String var myCar = { type : 'hatchback', color : 'blue', year : '2012' }; -Object var myCar = true; -Boolean var myCarModel = 2012; -Number var myCars = ['hatchback', 'SUV', 'coupe', 'subcompact', 'sedan']; -Array

Match each code example with the appropriate type of variable String Object Boolean Number Array var myCar = { type : 'hatchback', color : 'blue', year : '2012' }; var myCars = ['hatchback', 'SUV', 'coupe', 'subcompact', 'sedan']; var myCar = true; Number var myCarModel = 2012; var myCarModel = 2012; var myCar = 'hatchback';

var myString = 'You don\'t need to worry about \'escaping\' quotes in JavaScript.'; var myString = 'You don\'t need to worry about "escaping" quotes in JavaScript.';

Select which of the below code samples feature a correct way to use escape characters in a string. Pick as many or as few as you wish. var myString = 'You don't need to worry about "escaping" quotes in JavaScript.'; var myString = 'You don/'t need to worry about /"escaping/" quotes in JavaScript.'; var myString = 'You don\'t need to worry about \'escaping\' quotes in JavaScript.'; var myString = 'You don\'t need to worry about "escaping" quotes in JavaScript.'; var myString = "You don't

False

What would the boolean value of the variable areTheyTheSame be, given the following JavaScript? var areTheyTheSame; var myNum1 = '5'; var myNum2 = 5; if (myNum1 === myNum2){ areTheyTheSame = true; } else { areTheyTheSame

use either 'single' or "double" quotes, as long as you are consistent.

When dealing with strings in JavaScript, it is considered best practice to... use 'single' quotes. use either 'single' or "double" quotes, as long as you are consistent. avoid using quotes to encapsulate string values. use either 'single' or "double" quotes in the same script depending on how you feel at the time. use "double" quotes.

True

When you concatenate a string with a number as in the code below, the data type of the resulting variable will be "string." var myAddress = 35 + ' Roger Rd. E.';

selectedColor datePicked

Which of the following are suitable variable names? Pick as many as you wish. _myVar var selectedColor datePicked 12thItem

var coffeeType = "Dark roast";

Which of the following blocks of code declares and initializes a variable? coffeeType === "Dark roast"; var coffeeType >= "Dark roast"; var coffeeType; coffeeType = "Dark roast"; var coffeeType = "Dark roast";

var trophyName = "The Memorial Cup"; var trophyName = trophyName.replace('Memorial', 'Stanley');

Which of the following blocks of code will replace the substring, "Memorial" with "Stanley" in the variable trophyName? var trophyName = "The Memorial Cup"; var trophyName = replace(trophyName, 'Memorial', 'Stanley'); var trophyName = "The Memorial Cup"; var trophyName = trophyName.indexOf('Memorial', 'Stanley'); var trophyName = "The Memorial Cup"; var trophyName

!==

Which of the following symbols represents the strict non-equality comparison operator? =!= !== =! != ==!


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

Weather Test Unit Review Questions

View Set

BUS251: Chapter 39 Reading & Assessment Questions

View Set

NU372 HESI Case Study: Management of a Medical Unit

View Set

FoRT Practice Test questions 1-68

View Set