JavaScript Flashcards

1
Q

Operators

  • &&
  • ||
  • !
  • ==
  • !=
  • ===
  • !==
A

most logical operators automatically convert types:

  • && and (FALSE overrides)
  • || or
  • ! inverts boolean value
  • == equals
  • != not equals
  • ===
  • !==
  • 5 < “7” is true
  • 42 == 42.0 is true
  • “5.0” == 5 is true
  • === and !== are strict equality tests; checks both type and value ”5.0” === 5 is false
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the Prototype JavaScript Framework?

A

The Prototype JavaScript library adds many useful features:

  • many useful extensions to the DOM
  • added methods to String, Array, Date, Number, Object
  • improves event-driven programming
  • many cross-browser compatibility fixes
  • makes Ajax programming easier
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is client-side scripting?

A
  1. Browser requests a document from a web server using a specific URL
  2. Web server sends back the site
  3. Then, browser interprets and executes the page including any script code that manipulates the page
  4. The scripts already reside on the client browser
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are client-side scripts?

A
  • Scripts are embedded within and interact with HTML, selecting elements of it, then manipulating those elements to provide an interactive experience.
  • Scripts interact with CSS
  • Scripts put less stress on the server
  • Faster response than from web server
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

server-side programming (PHP) benefits

A
  • create dynamic web pages
  • more secure: client can’t see source code
  • not subject to browser compatibility issues
  • powerful: can write files, open connections to servers, connect to databases, etc.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

client-side scripting (JavaScript) benefits:

A
  • can modify a page without having to post back to server (faster UI - bettter usability)
  • event-driven: can respond to user actions (e.g. clicks)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How is JavaScript linked in HTML?

A

script src=”filename” type=”text/javascript”>

  • placed in HTML head
  • script code is stored in a separate .js file
    • can be inside HTML file, like CSS, but not recommeded
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is JavaScript + uses?

A

a lightweight intepreted object-oriented programming language (“scripting language”)

  • adds interactivity
  • react to events (e.g. onlick)
  • creates cookies
  • validates forms (and other calculates)
  • create animations
  • get user information about a user’s computer (e.g. browser type)
  • a web standard (though not supported by all browsers)
  • add html on the fly
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Problems of JavaScript

A
  • the DOM can be clunky to use
  • code portability not guaranteed across browsers
    • solution: some problems can be avoided with hacks (checking if browser is IE, etc.)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

JavaScript vs. PHP

(similarities & differences)

A

Similarities:

  • both are interpreted, not compiled
  • both are relaxed about syntax, rules, and types
  • both are case-sensitive
  • both have built-in regular expressions for powerful text processing

Differences:

  • JS is more object-oriented: noun.verb(), less procedural: verb(noun)
  • JS focuses on user interfaces and interacting with a document; PHP is geared toward HTML output, databases and file/form processing
  • JS code runs on the client’s browser; PHP code runs on the web server
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

process of event-driven programming

A
  1. user interacts with page
  2. an “event” occurs
  3. A piece of JS code runs in response
  4. the page updates
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

give an example of an event handler

A

onclick is an example of an event handler, a ‘responsive’ JavaScript function

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

synchronous vs asynchronous web communication

A

Synchronous web communication (click, wait, refresh)

Asynchronous web communication (user can keep interacting with page while data loads) – made possible by AJAX

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Describe a Web Application

A

Web applications are dynamic websites that mimics the feel of a desktop app and presents a continuous user experience rather than disjoint pages by downloading data from a server in the background (e.g., Google Docs).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is AJAX

A

Ajax is useful for web applications.

  • Asynchronous JavaScript and XML
  • Enables asynchronous web communciation
  • NOT a programming language
  • A way of using JavaScript
  • Ajax can only fetch files from the same server that the page is on
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What are undefined and null values

A

undefined: has not be declared, does not exist

null: exists, but was specifically assigned an empty (null) value

17
Q

describe the following parts of JS:

s1.charAt(1)

A

charAt(1) is a function because of the ()

s1 is an object because it has a . after it

18
Q

give 3 examples of how javascript would change html

A

1. change html content when an event occurs

button type=”button” onclick=’document.getElementById(“demo”).innerHTML = “Hello JavaScript!”’>Click Me!

2. change html attribute when an event occurs (e.g. update shopping card item number)

3. show hidden hmtl content when an event occurs (previoulsy hiddent content appears)