Using JavaScript with HTML

Ace your homework & exams now with Quizwiz!

What window object property likely produces the following output? Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 Chrome/53.0.2785.116 A. navigator.UserAgent B. navigator.language

A

console.warn()

Sometimes a developer may assume a variable has a certain value. The console.warn() method can be placed in strategic places in the code to indicate when those assumptions are not true.

console.error()

The console.error() method can be called to display the state of the code for debugging. A well written error message can be used by the developer to reproduce the problem and fix the bug.

(t/f)When writing custom JavaScript, the defer attribute is usually better than the async attribute.

When writing custom JavaScript, the defer attribute is usually better than the async attribute. Custom JavaScript can take advantage of concurrent processing with HTML. As a result, a developer may see better performance using the async attribute instead of the defer attribute.

js defer attribute

allows the browser to load the web page concurrently with loading the JavaScript but the JavaScript is not processed until the web page is completely loaded.

js async attribute

allows the browser to process the web page concurrently with loading and processing the JavaScript.

console.dir()

console.dir() is useful to display structured data (e.g., JSON).

API methods

console.log() displays informational data to the console. console.warn() displays warnings to the console. The browser usually has a special indicator to differentiate a warning from the standard log message. Ex: A yellow warning box. console.error() displays errors to the console. The browser usually has a special indicator to differentiate an error from a warning or the standard log message. Ex: A red error box. console.dir() displays a JavaScript object to the console. The browser usually supports a method for compactly representing the object. Ex: a hierarchical tree representation allowing a developer to expand and collapse the object contents.

Document Object Model (or DOM)

data structure that represents all parts of an HTML document

(t/f)A web browser will process the HTML following a script element that uses an external JavaScript file while the browser waits for the web server to return the JavaScript file.

f

(t/f)One script element can be used to reference multiple external JavaScript files

f

(t/f) window object is a property of the document object

f; The document object is a property of the window object can be accessed as window.document

(True False) One script element can be used to include both inline JavaScript and a reference to an external JavaScript file.

false

What window object property is useful for determining if the web page is loaded using HTTPS or HTTP? A. location B. navigator

location

window.location

location object that contains information about the window's current URL Ex: window.location.hostname is the URL's hostname

window.navigator

navigator object that contains information about the browser. Ex: window.navigator.userAgent returns the browser's user agent string.

js Minification or minimization

process of removing unnecessary characters (like whitespace and comments) from JavaScript code so the code executes the same but with fewer characters

window object

represents an open browser window

javaScript object document

represents the DOM of the html

JavaScript obfuscator

software that converts JavaScript into an unreadable form that is very difficult to convert back into readable ex: Developers obfuscate a website's JavaScript to prevent the code from being read or re-purposed by others.

API (Application Programming Interface)

specification of the methods and objects that defines how a programmer should interact with software components.

(T/F) JavaScript accesses and manipulates the DOM to make web pages interactive

t

(t/f)Window object properties or methods can be accessed without putting window. in front of the property or method. True False

t

(T/f)When using a third-party JavaScript library, the defer attribute is usually better than the async attribute

t; A third-party JavaScript library may assume that the DOM is already loaded. Thus, the defer attribute ensures the DOM is loaded before the JavaScript. However, a well written library will not make assumptions about the DOM availability.

window.innerHeight window.innerWidth

the height and width in pixels of the window's content area. Ex: window.innerWidth returns 600 if the browser's content area is 600 pixels wide.

console.log()

useful for printing debugging messages that help the programmer. console.log is also helpful for seeing simplified visualizations of JavaScript data or parts of the DOM.


Related study sets

LPN to RN Transition - Fundamentals - Chapter 1: Introduction to Nursing

View Set

CITI - SoCRA - GCP for Clinical Trials with Investigational Drugs and Biologics (ICH Focus)

View Set

Gastrointestinal Practice Question

View Set

Chapter 14-World War I and Its Aftermath

View Set

exam 2 SAMPLE QUESTIONS FROM DR .YOUAN'S LECTURE

View Set

BUSM 501 Midterm Exam Chapters 3,6,8

View Set

Continuidad de los Parques Análisis

View Set