N341 Midterm

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

logical NOT

!

is not equal to

!=

strict not equal to

!==

Which of the following is a truthy value? ( 0, a variable with no value assigned to it, empty value, NaN (Not a Number), "false")

"false"

Document Object Model

page title, last modification date, getElementById() method

The Document Object Model (DOM) _____. (3 answers)

specifies how JavaScript can change the html page, specifies how the browser should make a model of the html page, is a tree-like structure

Scripts are made up of _____ instructions

step-by-step

Check each line of code that correctly sets strMessage to a string value:

strMessage = 'Sally said, "hello!" '; strMessage = "Sally said, \"hello!\" ";

The break keyword tells the JavaScript interpreter _____ . (2 answers)

that is has finished with a switch statement, to go to the first line of code that appears after a loop or switch statement

A switch statement works like a series of if statements. The difference is that the switch statement performs more quickly.

true

A unary operator returns a result using just one operand.

true

After a DOM query, if your script needs to use the result more than once, it is a good idea to store the location of the element(s) in a variable. This is known as caching the selection.

true

All major browsers include a JavaScript interpreter that translates your code into instructions the computer can understand.

true

Computers use data to create simplified models of objects in the human world

true

Event listeners are not supported in some older browsers, so it is necessary to provide fallback code if support for those browsers is necessary.

true

Which two of the following steps must be completed to add an element to the page using DOM manipulation?

Create the element - createElement() Add the element to the DOM - appendChild()

What are the main types of DOM nodes?

Document node, Element nodes, Attribute nodes, Text nodes

3 statements about type coercion:

It creates a need for using strict equality operators, It can lead to unexpected values in your code, It can lead to errors.

interactivity or behavior of the page

JavaScript

_____ events occur when the user interacts with the keyboard.

Keyboard

For separation of layers, which is the preferred method for using JavaScript with your html page?

Link to an external file.

logical AND

&&

An array can be a list of numbers or strings, but not a list of objects.

False

When JavaScript is used to change the appearance of a web page, the original html file is also changed.

False

Writing comments inside a script is a way to explain what the code is doing. The JavaScript interpreter carefully reads each comment to get detailed information.

False

_____ events occur when an element gains or loses focus.

Focus

_____ events occur when the user interacts with a form element.

Form

HTML attribute; Old technology - DO NOT USE

HTML Event Handler

In JavaScript, what does the operator ++ do?

It adds one to the current number.

In JavaScript, what does the operator + do? (2 answers)

It concatenates two strings. It adds two numbers.

_____events occur when the user interacts with the mouse, trackpad, or touchscreen.

Mouse

In the following example, intTotal = 2+4*10;

Multiplication happens before addition.

_____ events occur when the DOM structure has been changed by a script.

Mutation

Within an object, the value of a property can be a _____.

Number, another object, String, Boolean, Array

_____ is a list of values. It is helpful for storing a list of related items.

An Array

Which of the following is NOT a type of JavaScript operator? (Assignment operator, Comparison operator, Sign operator, Arithmetic operator, Logical operator, String operator)

Sign operator

Global JavaScript Objects

String, number, math, and date objects

When evaluating a condition with a comparison operator, the result will be a _____.

boolean

Two keywords that are often used with loops are:

break; continue

Properties and methods of an object are accessed using _____.

dot notation

document.write()

easy way for beginners to learn to add content to a page using this technique after the page has loaded can cause it to overwrite the entire page

The process of creating a single listener on a parent event is called _____.

event delegation

All JavaScript element selection methods are supported equally well in every major browser.

false

Once a script begins to run, the entire sequence must finish. Neither the user nor the programmer can influence it.

false

Using a flowchart is a bad way to work out how the tasks of a script fit together to achieve the desired goal

false

When an event has occurred, it is said to _____. Events are said to _____ a function or script. When it is indicated which event will cause a response on a selected node, it is said to _____ an event to a DOM node.

fire or raise; trigger; bind

Which of the following are focus & blur events?

focusin, focusout, blur, focus

A function that appears where the interpreter expects to see an expression is called a _____ .

function expression

innerHTML

gets/sets text and markup but has security risks

textContent

gets/sets text only from the containing element

Using global variables can lead to errors and slowly performing scripts because _____. (2 answers)

global variables use more memory than local variables global variables can have naming collisions with other scripts

A variable that is declared outside a function can be used anywhere in the script. It is called a _____ variable and has _____ scope.

global; global

The Math object _____. (3 answers)

has a method that generates a random number is used with the name of the Math object followed by the needed property or method. For example, numTwo = Math.sqrt(4); is a global object

Objects _____. (4 answers)

have variables that become known as properties group together a set of variables and functions have functions that become known as methods create a model of something you would recognize from the real world

structure or content of the page

html

does not work with IE8 or earlier; can attach multiple functions to an event

DOM Level 2 Event Listener

When developing a script, the programmer should typically follow what iterative process?

Define the goal, design the script, code each step

When an event occurs, the event object tells _____. (3 answers)

information about the event the type of event that was fired information about the element that triggered the event

There are two very different approaches to changing content on a DOM tree: _____ property and DOM manipulation. _____ easily targets individual nodes in the DOM tree, whereas _____ is better suited to updating entire fragments.

innerHTML, DOM manipulation, innerHTML

Event used with ˂input˃ and ˂textarea˃ elements

input

The following line of code sets a variable to a numeric value:

intQuantity = 7;

interactivity or behavior of the page

javascript

If different parts of a script need to perform the same task, writing a function will _____. (3 answers)

keep the code shorter, make the script easier to read, avoid unnecessarily repetitive code

Which of the following are keyboard events?

keyup, keydown, keypress, input

The following html code: <scrpt src="js/webPageBehavior.js"></scrpt>

links to a JavaScript file from an html page.

var myPhone {}; uses _____ to create a _____.

literal notation; empty object

To apply the same code to numerous elements in a NodeList _____ is a powerful technique. First, it is necessary to determine how many items are in the NodeList. This is done with the _____ .

looping through; length property of the Nodelist

var intA = 1; // first operand in the condition var intB = 2; // second operand in the condition var intC = 3; // third operand in the condition if (!(intA < intB)) { doStuff(); } // end if In the example above, doStuff() will _____.

never be called

Three data types that JavaScript uses are

numeric, string, and Boolean

In the following lines of code, the value of strMyFavoriteColor is _____. var strColors = new Array('red', 'white', 'blue'); strMyFavoriteColor = strColors[0];

red

The response that a function provides when it is called is a _____.

return value

The location of a variable declaration will affect where it can be used within the code. This is known as the variable's _____.

scope

Event handling involves three steps. Put these steps in the order they must appear in the code.

select an element node; bind an event to the node; specify the code that is to run

Each individual instruction in a script is known as a statement. Statements should end in a ____. This allows both the human and the computer to understand the code.

semicolon

var strMessage = 'Hello World'; (2 answers)

strMessage can use the built-in properties and methods of the String object. strMessage.length returns the length of the message - which is 11.

Event used to check the values a user has entered into a form before sending it to the server

submit

var intA = 1; // first operand in the condition var intB = 2; // second operand in the condition var intC = 3; // third operand in the condition var intD = 4; // fourth operand in the condition if ( (intA < intB) || (intC > intD) ) { doStuff(); } // end if else { doDifferentStuff(); } //end else In the example above, _____. (2 answers)

the condition (intC > intD) is not checked, doStuff() is always called.

A DOM query can return either one element or a collection of nodes.

true

A browser uses different parts of the script - depending on how the user interacts with the web page

true

A script is a series of steps that a computer can follow to achieve a goal

true

Once an element node is selected, it is possible to select other nodes related to it. This is called traversing the DOM. New elements can be selected based on their relationship as a parent, sibling, or child of the originally selected element.

true

Once an element node or group of nodes is selected, the attributes, the child elements, and the text content can be changed.

true

Some browsers treat whitespace between elements as a text node. So, a DOM query can return different elements in different browsers.

true

The Document Object Model is a tree-like structure that the browser constructs when rendering a web page.

true

The preventDefault() method of the event object changes the default behavior of an element. This can be used to keep the user on the page after clicking on a link.

true

When learning a new computer language, it's important to learn both the vocabulary and syntax

true

The keyword this ______? (3 answers)

usually refers to the object in which the function operates. refers to the window object when used in a global context has a value that changes in different situations.

In JavaScript, the _____ keyword is used to declare variables.

var

Computers use _____ to store data for use in computations or for later reference.

variables

In JavaScript, the following code will _____. var intSize = 5; intSize += 3;

will add 3 to intSize.

Browser Object Model

window location, scrolling distance, and alert() method

Sections of statements called code blocks are surrounded by _____. This creates a group of statements and helps to make scripts more readable.

{ curly braces }

logical OR

||

less than

<

less than or equal to

<=

is equal to

==

strict equal to

===

greater than

>

greater than or equal to

>=

The following rules apply when giving a variable a name.

The name must not contain a dash or a period. All variables are case sensitive. The name must not start with a number.

strong support in all major browsers; can only attach a single function to an event

Traditional DOM Event Handler

Multi-line comments start with /* and end with */. These comments can span many lines and are often used to describe how the script works.

True

Operators and expressions allow programmers to create a single value from one or more values.

True

Single-line comments begin with two forward slash characters. They are usually used to provide short descriptions of what the code is doing.

True

To use the built-in Date object in JavaScript, it is necessary to create an instance of the Date object using the constructor method.

True

Two essential steps to using variables are to declare them and to assign them a value.

True

Using the <scrpt> tag to include JavaScript inside an html file can affect the loading time of the page.

True

_____ events occur when the user interacts with the browser's UI rather than the web page.

User Interface

A series of statements that have been grouped together to form a specific task is called _____.

a function

Which of the following is a falsy value? ("false", any number that is not zero, "0", strings with content, a variable with no value assigned to it)

a variable with no value assigned to it

Cross-Site Scripting Attacks (XSS) involve an attacker placing malicious code into a site. Using the innerHTML property to allow user input is one way to enable these attacks. XSS can allow an attacker to _____. (6 answers)

access the user's login information access form data access the site's cookies post unwanted content spread malicious code make purchases with the user's account

Which of the following files are written as plain text? (html, css javascript)

all of them

Which of the following files are written as plain text? (html, css, javascript)

all of them

The following line of code is an example of _____. var strColors = new Array('red', 'white', 'blue');

an array constructor

The following line of code is an example of _____. strColors = ['red', 'white', 'blue'];

an array literal

To access the elements on the DOM tree, JavaScript can be used to select _____. (4 answers)

an individual node by element id, multiple nodes by tag name, using CSS selector syntax, multiple nodes by class

To organize your data, you can either use an array or use an object to group a set of related values. If the order of the items is important, it is better to use an _____.

array

DOM Manipulation

best technique to use when changing one element that has many siblings does not affect event handlers if many changes are needed, it needs more code and is slower than other methods

The following line of code sets a variable to a Boolean value:

blnIsBlue = true;

element.innerHTML

can be used to add lots of new markup using less code than other options simple way to remove all content from one element (by assigning it a blank string)

Event used when the status of form elements have been altered

change

for loop

code needs to be run a specific number of times

while loop

code needs to be run an unknown number of times

do while loop

code needs to be run at least once

When creating lots of objects with similar functionality, it is good to use _____.

constructor notation

var myPhone = new Object(); uses _____ to create a _____.

constructor notation; empty object

var myPhone = new Phone(ꞌmobileꞌ, ꞌ3175551212ꞌ, 200); uses _____ to create a _____.

constructor notation; instance of an object

style or presentation of the page

css

Which loop has the statements in the code block before the condition?

do while


Set pelajaran terkait

module 8 - sensation and absolute threshold,

View Set

Cisco RSE Chapter 10 Quiz(Module 14)

View Set

CTB: Cartilage, Bone, Diffusion and Osmosis

View Set

Chapter 11 Mastery Progress Exam

View Set

Chemistry -- Terms and Definitions

View Set