Chapter2 CIST 1520 (JavaScript)

Ace your homework & exams now with Quizwiz!

Which of the following creates an empty string? A. null B. undefined C. "" D. 0

"" same type of quotation marks var emptyString = "";

Which of the following is an arithmetic binary operator? A. + B. II C. = D. &&

+

What is a concatenation operator? A. > B. + C. I I D. ++

+ used to combine two strings var destination = "Honolulu"; var location = "Hawaii"; destination = destination + "is in" + location;

Which of the following is an arithmetic unary operator? A. ++ B. II C. = D. &&

++ requires just a single operand. myNumber++; changes the value of the mynumber variable to 101

Which of the following is an integer? A. -2.5 B. 6.02e23 C. -11 D. 0.03

-11

Explains the difference between global and local variable, and describe how using or not using the var keyword affect the scope of a variable.

-Global - variable is declared outside a function, can be used throughout the program -Local - declared inside a function and only use within the function local scope. -You must use the var keyword when you declare a local variable. However when you declare a global variable the var keyword is optional. - It is better programming technique to always use the var keyword

What alternative exist to specifying an event handler using an HTML attribute?

1. To specify the function as a property value for the object representing the HTML element. Each element has an onevent property for each event it supports. 2. the addEventListener() method, which is available for every webpage element.

How is the expression 5+2*8 evaluated?

2*8 = 16 then 16+5 = 21.

What is an empty string?

A zero-length string assigned as a value of a string variable

Why does a named function not execute automatically. And how do you execute it?

Because creating a function only names the function, specifies its parameters, and organize the statement it will execute. To execute, you need to invoke or call it.

Why do you sometimes need to insert an extra space in a string when using concatenation operator?

Because the last character of the first value is directly followed by the first character of the second value

What is the difference between a binary operator and unary operator?

Binary = requires an operand before and after the operator. Unary = just a single operand either before or after the operator.

Which of the following is a primitive data type in JavaScript? A. Boolean B. Integer C. Floating-point D. Logical

Boolean

What is a falsy value? What are the six falsy values in JavaScript?

Boolean value false. 1. "" 2. -0 3. 0 4. Nan 5. null 6. undefined

How do you view any error messages that a browser might generate when processing your code?

Browsers display error message in a pane known as a browser console. Use keyboard shortcut or menu command to make the console visible.

When performing operations with operators in the same precedence group, how is the order of precedence determined?

By the operator's associativity - from left to right or right to left, depending on the operator involved

Which one of the following creates a local variable? A. Declaring it outside of a function with the var keyword. B. Declaring it outside of a function without the var keyword. C. Declaring it inside a function with the var keyword. D. Declaring it inside a function without the var keyword

Declaring it inside a function with the var keyword

What is the difference between an integer and a floating-point number?

Integer = positive or negative number with no decimal places A Floating-point - number that contains decimal places or that is written in exponential notation.

What is the result of 5%4? Name the operator and explain the steps you took to arrive at your answer.

It is a modulus operator. It divides one operant by another operand and returns the remainder. 5/4 = 1 remain 1. The remainder is the result.

Why is it poor programming practice to declare a global variable inside of a function by not using the var keyword?

It makes it harder to identify the global variable in your script

What is comparison operator (rational operator)? What kind of value does it returns?

It used to compare two operands and determine if one value is greater than another. A Boolean value of true or false is returned after two operands are compared

Which of the following describes JavaScript? A. Strongly typed B. Statically typed C. Loosely typed D. Untyped

Loosely typed because data type can change after they are declared.

What is the difference between a named function and an anonymous function?

Named function - a set of related statement that is assigned a name Anonymous function - a set of related statement with NO name assigned to it

Explain the difference between prefix and postfix operators, and provide an example of each.

Prefix - operator is placed before a variable name Example: ++count; postfix - operator is placed after a variable ex. Example: count++;

How does JavaScript deal with code that performs arithmetic operation on string values?

The string are combined instead of being added together.

Which of the following is the JavaScript escape character? A. " B. ' C. \ D. /

\ tells the compiler + interpreter that the character that follows has a purpose. mom\'s = single quotation mark (apostrophe)

Which of the following is a valid JavaScript statement? A. document.write('Boston, MA is called 'Beantown'') B. document.write("Boston, MA is called "Beantown"") C. document.write("Boston, MA is called 'Beantown"') D. document.write("Boston, MA is called 'Beantown'")

document.write("Boston, MA is called 'Beantown' ")

What is the result of the statement 5<4 A. 1 B. yes C. true D. false

false < returns true if the left operand is less than the right operand

A(n)___ allows you to execute a related group of statements as a single unit. A. variable B. statement C. event D. function

function

Write a function that includes the following parts and then label the parts: Name, Parameters, Function braces, Function statements

function calculateVolume(length, width, height){ var volume = length * width * height; document.write(volume); } function name_of_function (parameters) {brace statements; }

A variable that is declared outside a function is called a(n)___ variable A. class B. local C. global D.program

global

What is the result of the following expression? Name the operators, and explain the steps you took to arrive at your answer. 5>4 ? document.write("green") : document.write("blue");

green 5 is greater than 4. That is a conditional expression, which evaluates to true. Therefore the expression 1 (document.write ("green") executes.

Parameters in a function definition are placed within___ A. braces B. parentheses C. double quotes D. single quotes

parentheses ()

Which of the following is a Boolean value? A. 3.04 B. true C. "Greece" D. 6.02e23

true

Which possible value can a Boolean variable have?

true or false


Related study sets

Unit 2 Part 2 America's First National Government - The Articles of Confederation

View Set

Ch. 59: Assessment and Management of Problems Related to Male Reproductive Processes

View Set

introduction to nursing (SHERPATH) WEEK 7 & 8

View Set

NISSAN CONNECTIVITY - BROUGHT IN

View Set

Chapter 13: Nursing Care During Newborn Transition

View Set

management and production test 2

View Set