Intro Flashcards

1
Q

JavaScript

A
  • a scripting language meaning that it does not need compile

- programming language that provides instructions to a web browser

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

Ways to include JavaScript in your page

A

alert(“Hello Everybody”)

-use the script tags and place in the JS methods.

or use the source attribute as long as js file is in the same directory.

src= “alert.js”

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

Datatypes

A

-specialized form of information.

-string: sequence of characters
-number: integer and floats
-boolean
-object: represents a group of key/value pairs
-date: represents date/time
-array: represents a collection of data
var arr= [1,’232’,582]

  • undefined: value not yet defined
  • null; empty value
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

variable

A

a temporary storage unit that stores data

ex: var variableName;

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

JS Naming rules

A
  1. follow camelCase convention (start w lower case)
  2. names must begin w letter, _, or $
  3. numbers and Unicode escape sequence can be used after the first character
  4. names are case sensitive
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

variable value assignment

A

-use = sign then brackets
examples:

var name = "Jennifer";
var num = 3;
ex: var carSpecs = {
numWheels: 4,
engine: 'V6',
interior: 'cloth'
};
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Single and multiline comments

A

single - //

multiline - /*comment */

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

to print to console

A

console.log(“”);

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

creating function

A

group of block statements

use function keyword:

      function talk() {
              alert("Hello!");
        }
    talk();
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Hoisting

A
  • a variable declared without using the var keyword, makes it available outside of the function
  • hoisting is the process of assigning loose variables to the global window object
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Creating objects using literal notation

A

objects are key/value pairs

ex: var Person = {
numWheels: 4,
property: value,
property: value
};

OR use objects constructor

ex: var Person = new Object();

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

dot notation

A

access properties of an object using a dot

Person.name = “Adam”;

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

array notation

A

access properties using brackets

ex: Person[“name”] = “Adam”;

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

defining a method

A

a method that is assigned as property of an object

var Person = {
givenName: function {
         //....
      }
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

this keyword

A

this keyword refers to the current executing context but outside of it, it refers to the global window object

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

HTML DOM - Document Object Model

A

**It is the programming interface that allows you to retrieve and manipulate elements of a webpage; otherwise referred to as document. **

**DOM, provides a tree-like structure or representation of all of the elements and their corresponding content of a webpage. Each element is referred to as a node. **

A browser’s DOM also provides methods for adding/removing/editing content. It provides what we call an API, which stands for Application Programming Interface

17
Q

API - Application Programming Interface

A

An API is like a recipe book that lists several methods used for a particular purpose. In our case, we use the API to manage elements on a webpage as well as manage user interactions such as button clicks.

18
Q

Accessing the DOM methods

A

specific methods that are used to retrieve elements or arrays of elements from the webpage document.

getElementById - will retrieve the first matched element with the specified id.

var doc = document.getElementById(“myID”)

getElementsByTagName – will retrieve an array of elements (list?) of the specified tag.

For example, you can retrieve all paragraphs on the page by passing in “p”, which corresponds to the paragraph tag.

getElementsByClassName – will retrieve an array (list?)of elements that have the specified class.

19
Q

Changing HTML : innerHTML

A
  • text-based elements have the property innerHTML that you can access to change the contained text
    element. innerHTML = “new content”;
20
Q

Changing HTML : setAttribute()

A
  • attributes can be set with this function

element. setAttribute(“name”, value);

21
Q

Changing CSS : use style property

A
  • use style property to change the CSS of an element

element. style.property = value;

22
Q

Adding/Deleting elements from a page/document methods

A

createElement()
creates an element of the specified tag

appendChild()
adds a child element to the one specified

removeChild()
deletes a child element of the one specified

23
Q

Event Handling - events definition

A

-events are actions that occurs, initiated by user or within browser

ex:
user clicking their mouse

24
Q

Event handlers

A

event handlers/listeners are
registered with a particular event and notify when an event occurs

listeners can be added to DOM elements

25
Q

Adding even listener

A

Use addEventListener method to register event

Click Me!!

var btn = document.getElementById(“clicker”);

btn.addEventListener(“click”, function() {alert(“The button was clicked!!!”) } );

26
Q

Event Names

A
  • click: occurs when user clicks their mouse
  • change: occurs when an option is selected from a dropdown
  • mouseover: occurs when a cursor is over an element
  • keydown: occurs when a key is pressed
  • load: occurs when element loads
  • focus: occurs when an element has focus
  • blur: occurs when an element loses focus
  • submit: occurs when a form is submitted
27
Q

Callback function

A

The function that we pass to addEventListener is called a callback function.A callback function is a function that is a parameter.Typically, the method will execute the callback after all of its other statements complete.Callbacks are used in several other types of methods as well.

28
Q

IE Nuiances

A

attachEvent() same as addEventListener() but in older versions

29
Q

prevent default actions

A

use preventDefault() to stop default event actions

same as….

use preventDefault() to stop execution of default actions associated with an event

30
Q

Event propagation

A

-how events are moved throughout elements in the browsers

31
Q

Event propagation

A

capturing() - phase of event propagation through DOM from the root to the node of the target

bubbling() - phase of event propagation outward from the target up the DOM to the root node

When an event first occurs,such as a user click,the event is emitted fromthe topmost element in theDOM, which is the window.And, it moves down thedocument tree structure until itreaches the origination or targetof the event. This iscalled capturing. The eventis emitted and captured atthe location of the target.In contrast, after capturing, thebubbling phase occurs and eventsare propagated back up theDOM until it reaches thewindow object. The event issaid to bubble up towindow. By default, event listenersare triggered on the bubblingphase.

32
Q

phase: either true (event triggered under capturing) or false (event triggered under bubbling)

A

By default, event listeners are triggered on the bubbling phase. To set the phase programmatically,you would add a thirdparameter to the addEventListenermethod and specify a Booleanvalue. If this value istrue, the listener is setto trigger under capturing, ifit is false it willtrigger under bubbling.