IES: JS-deck 11 Flashcards
1
Q
HTML onmouseup
A
- HTML event attribute
- JS significant: avoid for variable/function names
- occurs when mouse button released over element
- Syntax
(HTML)<element onmouseup="myScript">
(JS)object.onmouseup = function(){myScript};
(JS addEventListener() method)object.addEventListener("mouseup", myScript);
- Example
<p onmouseup="mouseUp()">Click the text!</p>
- (Call a function when releasing a mouse button over a paragraph)
2
Q
HTML onmouseover
A
- HTML event attribute
- JS significant: avoid for variable/function names
- occurs when mouse pointer enters an element
- often used with onmouseout event
- similar to onmouseenter event: difference is onmouseenter event doesn’t bubble (relay info and influence up doc hierarchy).
- Syntax
(HTML)<element onmouseover="myScript">
(JS)object.onmouseover = function(){myScript};
(JS addEventListener() method) object.addEventListener(“mouseover”, myScript); - Example
<img onmouseover="bigImg(this)" src="smiley.gif" alt="Smiley">
- (Calls a function when moving the mouse pointer onto an image)
3
Q
HTML onmouseout
A
- HTML event attribute
- JS significant: avoid for variable/function names
- occurs when mouse pointer moves out of element.
- often used together with onmouseover event
- onmouseout event similar to onmouseleave: difference is onmouseleave doesn’t bubble (does not relay info and influence up the document hierarchy).
- Syntax
(HTML)<element onmouseout="myScript">
(JS)object.onmouseout = function(){myScript};
(JS addEventListener() method)object.addEventListener("mouseout", myScript);
- Example
~~~
<div>
<p>I will demonstrate onmouseout!</p>
</div>
~~~
* (example demonstrates the onmouseout event)
4
Q
HTML onmousemove
A
- HTML event attribute
- JS significant: avoid for variable/function names
- occurs when the pointer moves over an element
- Syntax
(HTML)<element onmousemove="myScript">
(JS)object.onmousemove = function(){myScript};
(JS addEventListener() method)object.addEventListener("mousemove", myScript);
- Example
<div onmousemove="myFunction()">Move the cursor over me</div>
- (Call a function when moving the mouse pointer over a
<div>
element)
5
Q
HTML onchange
A
- HTML event attribute
- JS significant: avoid for variable/function names
- occurs when HTML element value changes.
- similar to oninput event: difference is oninput occurs immediately after element value changed
- onchange occurs when element loses focus, after the content has been changed.
- other difference- onchange works on
<select>
elements - Syntax
(HTML)<element onchange="myScript">
(JS)object.onchange = function(){myScript};
(JS addEventListener() method)object.addEventListener("change", myScript);
- Example
<input type="text" onchange="myFunction()">
- (Calls a function when input field content changes)
6
Q
HTML onreset
A
- HTML event attribute
- JS significant: avoid for variable/function names
- occurs when a form is reset
- Syntax
(HTML)<element onreset="myScript">
(JS)object.onreset = function(){myScript};
(JS addEventListener() method)object.addEventListener("reset", myScript);
- Example
~~~
<form>
Enter name: <input></input>
<input></input>
</form>
~~~
* (Call a function when a form is reset)
7
Q
HTML onsubmit
A
- HTML event attribute
- JS significant: avoid for variable/function names
- occurs when a form is submitted
- Syntax
(HTML)<element onsubmit="myScript">
(JS) object.onsubmit = function(){myScript};
(JS addEventListener() method)object.addEventListener("submit", myScript);
- Example
~~~
<form>
Enter name: <input></input>
<input></input>
</form>
~~~
* (Calls a function when a form is submitted)
8
Q
variable
A
- a container
- Common to every scripting and programming language
- data can be stored here and retrieved later
9
Q
“strongly typed” variables
A
- in most programming languages
- must declare the particular data type they may contain
- JS variables are not in this category
10
Q
“loosely typed” variables
A
- JS variables are in this category
- may contain any type of data
- much easier to use than “strongly typed” variables
11
Q
variable name
A
- an alias for the value it contains
- Used in script
- references its stored value
- to ease script understanding, choose meaningful ones
12
Q
variable data types, data descriptions, and data examples
A
- string
* a string of text characters
* Ex. ‘Hello World!’ - number
* an integer or floating-point number
* Ex. 3.142 - Boolean
* A true (1) or false (0) value
* Ex. true - object
* a user-defined or built-in object
* Ex. console - function symbol
* a user-defined function, a built-in function, or an object method
* Ex. log( ) - symbol
* a unique property identifier
* Ex. Symbol( ) - null
* absolutely nothing (not even zero)
* Ex. null - undefined
* a non-configured property
* Ex. undefined
13
Q
declaring JS variables
A
- begin with keywords:
1. “let”-can be reassigned new values as script proceeds - this declaration may create a variable with a value to be assigned later
- this declaration may include an instant value assignation (“initialized”)
- subsequent assignation of different data types later in the script can be made
2. “const”- (constant) does not allow values to be reassigned
3. “var”- (best avoided-deprecated?) Does not prevent same variable being declared again in the same context - current variable type can be revealed using “typeof.”
14
Q
The concatenation “ + “ operator
A
- used in these examples to output a combined text string
- “typeof” keyword reveals current variable type
- Ex.
console.log( ‘firstName: ‘ + typeof firstName )
console.log( ‘valueOfPi: ‘ + valueOfPi )
console.log( ‘isValid: ‘ + isValid )
15
Q
known error in JS regarding null
A
- variable assigned a null value is described as an object type
- (variable with a null value should be described as a null type?)