JS Exam study 1 Flashcards

1
Q

How do you alert the user?

A

alert()

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

How do you print to the console?

A

console.log()

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

How do you prompt the user?

A

prompt()

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

what is used to declare variables?

A

var

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

Javascript is dynamically typed, what does that mean?

A

A variable can hold a value of any type

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

Javascript is weakly typed, what does that mean?

A

JavaScript uses aggressive type conversion so that any expression can be evaluated, regardless of whether the types of the operands match.

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

What is explicit type conversion and how does it work?

A

parseInt() returns the integer equivalent of its argument (or NaN)
parseFloat()returns the Float equivalent of its argument (or NaN)
isNaN() returns true if the argument cannot by converted to a numb

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

What are arrays in javascript?

A

arrays are objects that can hold a mix of data types.

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

How do you initialize arrays?

A
You initialize them using array literals in square brackets or using new Array()
var a = [];
var a = new Array();
var a = [34, "hi", true]
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How do you access elements in an array?

A

a[1] = 67;

alert(a[1]);

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

How do you extend an array?

A

You can extend them simply by assigning to a new index

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

What to elements that are not defined yet return?

A

the special value undefined

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

What is the DOM and what does DOM stand for?

A

DOM stands for Document Object Model, and it is the browser’s internal representation of the page.

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

How is the DOM constructed?

A

The DOM is constructed from the page source as the page is loaded. It consists of a “tree” structure of Node objects. Each Node object represents a single HTML element (paragraph, image, etc.). The DOM can be changed in a JavaScript program after it is constructed.

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

How does JavaScript properly output data?

A

A javascript app rarely uses alert, prompt, or confirm, and console.log is for debugging. The “output” of a JavaScript app consists almost entirely of changes to the DOM.

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

How do you retrieve a node?

A
var node = document.getElementById("element id goes here")
returns node with matching id or null
17
Q

How do you retrieve an array like structure of nodes?

A

var nodes= document.querySelectorAll(“css selector goes here”)

returns a an array-like structure of elements that match the selector

can use nodes.length for the size, use a for loop to access each element

for(var i=0; i

18
Q

How do you change the contents of the node?

A

use the innerHTML field to change the contents of the node
- node.innerHTML = “New Message”
▪replaces contents with plain text
- node.innerHTML = “<p>New <a>Message</a></p>”
▪replaces contents with new nodes
- node.innerHTML = “”
▪deletes contents

19
Q

How do you change the style of the node?

A

use the style field to change CSS properties
- node.style.color = “red”;
- node.style.backgroundColor = “rgb(128, 0, 128)”
▪ note that hyphenated properties are changed to camel case

20
Q

How do you add or change HTML attributes?

A

use other fields to change or add HTML attributes

  • node.href = “http://www.google.ca”
  • node.title = “here’s a popup”
  • node.src = “images/newImage.jpg”
  • Important Exception…
    • To change the class
      attribute you have to use
      node.className(not
      node.class)
21
Q

What is associative array notation?

A

JavaScript object fields can be accessed using the dot operator or square brackets

E.g.
- node.style.color = “red”
is the same as
- node.style[“color”] = redoThe square bracket notation is