HTML Flashcards
Where do you put non-visible content about the HTML document?
head
Where do you put visible content about the HTML document?
body
Where do the head and body tags go in a valid HTML document?
html
What is the purpose of a declaration?
The declaration tells the web browser what html version the document is written in.
Give 5 examples of HTML element tags.
- head
- body
- img
- div
- p
What is the purpose of HTML attributes?
to give each element its own additional/unique information
Give an example of an HTML entity (escape character)
copyright, trademark
How do block-level elements affect the document flow?
block-level elements take up the whole line
How do inline elements affect the document flow?
inline elements only take up space they only need
What are the default width and height of a block-level element?
width is 100% of the viewport and height is the height of the content
What are the default width and height of an inline element?
width is width of the content and height is also the height of the content
What is the difference between an ordered list and an unordered list in HTML?
ordered lists with numbers while unordered lists with dots
Is an HTML list a block element or an inline element?
block
What HTML tag is used to link to another website?
anchor tag
What is an absolute URL?
points to an external application / location
What is a relative URL?
relative URLs’ path generally refers to a resource on the same machine as the current document.
How do you indicate the relative link to a parent directory?
../
How do you indicate the relative link to a child directory?
/
How do you indicate the relative link to a grand parent directory?
../../
How do you indicate the relative link to the same directory?
the file name
What is the purpose of an HTML form element?
it represents a document section containing interactive controls for submitting information
Give 5 examples of form control elements.
input, label, select, button, textarea
Give 3 examples of type attributes for HTML input elements
text, radio, checkbox
Is an HTML input element a block element or an inline element?
inline
What are the six primary HTML elements for creating tables?
table, thead, tbody, tr, th, td
What purpose do the thead and tbody elements serve?
help distinguish between the main content and the first / last rows
Give 2 examples of data that would lend itself well to being displayed in a table.
- Academic grades
2. Restaurant customers
What are the names of the individual pieces of a CSS rule?
selector, declaration, property, value
In CSS, how do you select elements by their class attribute?
.
In CSS, how do you select elements by their type?
element name
In CSS, how do you select an element by its id attribute?
#
Name three different types of values you can use to specify colors in CSS.
color keywords, rgb color values, hexadecimal color values
What CSS properties make up the box model?
content (width, height), padding, border, margin
Which CSS property pushes boxes away from each other?
margin
Which CSS property add space between a box’s content and its border?
padding
What is a pseudo-class?
class that allows you to change the appearance of elements when a user is interacting with them.
What are CSS pseudo-classes useful for?
event based styling
Name at least two units of type size in CSS
pixels, rem
What CSS property controls the font used for the text inside an element?
font-family property
What is the default flex-direction of a flex container?
row
What is the default flex-wrap of a flex container?
nowrap
Why do two div elements “vertically stack” on one another by default?
they are block level elements
What is the default flex-direction of an element with display: flex?
row
What is the default value for the position property of HTML elements?
static
How does setting position: relative on an element affect document flow?
It doesn’t
How does setting position: relative on an element affect where it appears on the page?
relative positioning moves an element in relation to where it would have been in normal flow.
How does setting position: absolute on an element affect document flow?
It is removed from the document flow entirely (They don’t exists)
any sibling elements will shift to the empty space
How does setting position: absolute on an element affect where it appears on the page?
gets positioned within the nearest non-static ancestor element
How do you constrain an absolute positioned element to a containing block?
you can set the parent element’s position to relative.
What are the four box offset properties?
top, bottom, left, right
What is the purpose of variables?
they are used to store information to be referenced and manipulated
How do you declare a variable
variable keyword: var, let, const
How do you initialize (assign a value to) a variable?
=
What characters are allowed in variable names?
letter, $, _, numbers (but not in the beginning)
What does it mean to say that variable names are “case sensitive”?
variables, function names, and any other identifiers must always be typed with a consistent capitalization of letters.
i.e. data does not equal Data
What is the purpose of a string?
storing and manipulating text
What is the purpose of a number?
math
What is the purpose of a boolean?
comparison (making decisions)
What does the = operator mean in JavaScript?
assignment
how do you update the value of a variable?
variable name and then an “=” with the new value.
What is the difference between null and undefined?
null means “no value” whereas undefined means that “the variable has not been declared, or has not been given a value”
Why is it a good habit to include “labels” when you log values to the browser console?∫
so we know the context of that value
Give five examples of JavaScript primitives.
number, string, boolean, null, undefined
What data type is returned by an arithmetic operation?
number
What is string concatenation?
putting strings together
What purpose(s) does the + plus operator serve in JavaScript?
concatenation
What data type is returned by comparing two values?
boolean
What does the += operator do?
you add the value of the variable to the value and reassign that value to the variable.
What are objects used for?
storing property and values
What are object properties?
a simple association between name and value
Describe object literal notation.
var student = {
}
How do you remove a property from an object?
delete operator
What are the two ways to get or update the value of a property?
dot notation, bracket notation
What are arrays used for?
it is used to store different elements, often when we want to store list of elements and access them by a single variable
Describe array literal notation.
var myArray = [ ] ;
How are arrays different from “plain” objects?
ordered (indexed), have a .length property
What number represents the first index of an array?
0
What is the length property of an array?
.length: returns the amount of elements in the array
How do you calculate the last index of an array?
myArray[myArray.length - 1]
What is a function in JavaScript?
set of statements that performs a task or calculates a value
Describe the parts of a function definition.
function keyword, parameters, function code block
Describe the parts of a function call.
functionName(parameter);
When comparing them side-by-side, what are the differences between a function call and a function definition?
parameters vs arguments, no function keyword, no codeblock
Why are function parameters useful?
you can reuse the function for any other relevant situation
What two effects does a return statement have on the behavior of a function?
ends the function, returns control of the calling function
Why do we log things to the console?
To check if the output is what we want.
What is a method?
method is a function value that is assigned to a property in an object.
How is a method different from any other function?
method is stored in an object
How do you remove the last element from an array?
.pop()
How do you round a number down to the nearest integer?
Math.floor( )
How do you generate a random number?
Math.random( )
How do you delete an element from an array?
.shift( ) & .pop( ) & .splice( )
How do you append an element to an array?
.push( )
How do you break a string up into an array?
.split( )
Do string methods change the original string? How would you check if you weren’t sure?
No, console.log original string
Roughly how many strings methods are there according to the MDN Web docs?
51
Is the return value of a function or method useful in every situation?
no
Roughly how many array methods are there according to the MDN Web docs?
38
What three-letter acronym should you always include in your Google search about a JavaScript method or CSS property?
M D N
Give 6 examples of comparison operators.
, >, ===, !==
What data type do comparison expressions evaluate to?
boolean
What is the purpose of an if statement?
it’s how computers make decisions
Is else required in order to use an if statement?
no
Describe the syntax (structure) of an if statement.
if (conditional) {
}
What are the three logical operators?
&&, | |, !
How do you compare two different expressions in the same condition?
logical operators
What is the purpose of a loop?
as long as the conditional is true, it runs the code block
What is the purpose of a condition expression in a loop?
stopping the loop
What does “iteration” mean in the context of loops?
one execution of the loop code block
When does the condition expression of a while loop get evaluated?
before the code block executes
When does the initialization expression of a for loop get evaluated?
before anything
When does the condition expression of a for loop get evaluated?
after the initialization expression and before the loop code block
When does the final expression of a for loop get evaluated?
after each code block is run
Besides a return statement, which exits its entire function block, which keyword exits a loop before its condition expression evaluates to false?
break;
What does the ++ increment operator do?
increment the value by 1
How do you iterate through the keys of an object?
for in loop
What are the four components of “the Cascade”?
Source order, Inheritance, Specificity, Important
What does the term “source order”’ mean with respect to CSS?
the order in which you write your code matters.
How is it possible for the styles of an element to be applied to its children as well without an additional CSS rule?
inheritance
List the three selector types in order of increasing specificity.
type, class, id
Why is using !important considered bad practice?
it messes with specificity
Why do we log things to the console?
To check if we get the desired output
What is a “model”?
representation of something larger (not the original thing)
Which “document” is being referred to in the phrase Document Object Model?
HTML
What is the word “object” referring to in the phrase Document Object Model?
JavaScript object
What is a DOM Tree?
objects that branch out modeling the DOM
Give two examples of document methods that retrieve a single element from the DOM.
.querySelector( ), .getElementById( )
Give one example of a document method that retrieves multiple elements from the DOM at once
.querySelectorAll( )
Why might you want to assign the return value of a DOM query to a variable?
so you can manipulate it in the future
What console method allows you to inspect the properties of a DOM element object?
console.dir( )
Why would a tag need to be placed at the bottom of the HTML content instead of at the top?
you need the HTML to load first
What does document.querySelector( ) take as its argument and what does it return?
string selector, element object
What does document.querySelectorAll( ) take as its argument and what does it return?
string, NodeList
What is the purpose of events and event handling?
handle user interactions
Are all possible parameters required to use a JavaScript method or function?
no
What method of element objects lets you set up a function to be called when a specific type of event occurs?
addEventListener
What is a callback function?
when a function gets passed in as an argument
What object is passed into an event listener callback when the event fires?
event object
What is the event.target? If you weren’t sure, how would you check? Where could you get more information about it?
is where the event occurred
What is the difference between these two snippets of code?
The second one calls the function meaning it will be executed before the event listener gets called
What is the className property of element objects?
class value take from the html element
How do you update the CSS class attribute of an element using JavaScript?
className, classList
What is the textContent property of element objects?
the text inside the elements
How do you update the text within an element using JavaScript?
textContent, innerText, innerHTML
Is the event parameter of an event listener callback always useful?
no
Would this assignment be simpler or more complicated if we didn’t use a variable to keep track of the number of clicks?
more complicated
Why is storing information about a program in variables better than only storing it in the DOM?
so we can use it again in the future
What does the transform property do?
applies a 2D or 3D transformation to an element
Give four examples of CSS transform functions.
rotate, scale, translate, skew
The transition property is shorthand for which four CSS properties?
delay, duration, property, timing-function
What event is fired when a user places their cursor in a form control?
‘focus’
What event is fired when a user’s cursor leaves a form control?
‘blur’
What event is fired as a user changes the value of a form control?
‘input’
What event is fired when a user clicks the “submit” button within a ?
‘submit’
What does the event.preventDefault( ) method do?
prevent any default actions from events
What does submitting a form without event.preventDefault() do?
refreshes the page
What property of a form element object contains all of the form’s controls?
element property
What property of a form control object gets and sets its value?
value property
What is one risk of writing a lot of code without checking to see if it works so far?
not knowing where your error is
What is an advantage of having your console open when writing a JavaScript program?
You can immediately recognize an error or incorrect output
Does the document.createElement() method insert a new element into the page?
no
How do you add an element as a child to another element?
appendChild()
What do you pass as the arguments to the element.setAttribute( ) method?
the attribute name and the value of that attribute
What steps do you need to take in order to insert a new element into the page?
create the element, append it to an already existing element
What is the textContent property of an element object for?
to change the text value of the element
Name two ways to set the class attribute of a DOM element.
setAttribute( ), className
What are 2 advantages of defining a function to create something (like the work of creating a DOM tree)?
reusable, easy to change
Give two examples of media features that you can query in an @media rule
hover, width
Which HTML meta tag is used in mobile-responsive web pages?
viewport meta tag
What is the event.target?
a reference to the object onto which the event was dispatched
Why is it possible to listen for events on one element that actually happen its descendent elements?
event bubbling
What DOM element property tells you what type of element it is?
.nodeName
What does the element.closest() method take as its argument and what does it return?
a css selector, the closest element
How can you remove an element from the DOM?
remove( )
If you wanted to insert new clickable DOM elements into the page using JavaScript, how could you avoid adding an event listener to every new element individually?
add an eventListener to the parent element
What is a breakpoint in responsive Web Design?
the point in which the page changes layout due to media queries
What is the advantage of using a percentage (e.g. 50%) width instead of a fixed (e.g. px) width for a “column” class in a responsive layout?
there are other large range of screens. If we use hard set px it only looks nice on the desired screen size
What is a method?
It is a function stored as a property in an object
How can you tell the difference between a method definition and a method call?
method call: has parentheses and dot notation
method definition: has function keyword and a code block
Describe method definition syntax (structure)
method: function ( ) { code }
Describe method call syntax (structure)
obj.method( )
How is a method different from any other function?
It is is stored in an obj rather than a variable.
What is the defining characteristic of Object-Oriented Programming?
objects can contain both data (as properties) and behavior (as methods)
What are the four “principles” of Object-Oriented Programming?
Abstraction, Encapsulation, Inheritance, Polymorphism
What is “abstraction”?
To make something complicated into something simple
What does API stand for?
Application programming interface
What is the purpose of an API?
communication between softwares
What is this in JavaScript?
An implicit parameter of a function
What does it mean to say that this is an ‘implicit parameter’?
It means that even though we don’t see the keyword this, it’s implied (built-in) inside of the function.
When is the value of this determined in a function; call time or definition time?
call time
How can you tell what the value of this will be for a particular function or method definition?
There is no way to find out what this is
How can you tell what the value of this is for a particular function or method call?
the object on the left side of the dot
What kind of inheritance does the JavaScript programming language use?
prototypal inheritance
What is a prototype in JavaScript?
an object that contains properties and methods that can be used by other objects
How is it possible to call methods on strings, arrays, and numbers even though those methods don’t actually exist on objects, arrays, and numbers?
prototypal inheritance
If an object does not have its own property or method by a given key, where does JavaScript look for it?
look at the prototype in the prototype chain
What does the new operator do?
Creates a new instance of an object that contains the prototype’s properties
What property of JavaScript functions can store shared behavior for instances created with new?
prototype property
What does the instanceof operator do?
tests to see if the prototype property of a constructor appears anywhere in the prototype chain of an object
What is a client?
a piece of computer hardware that accesses a service made available by a server as part of the client-server model of computer networks.
What is a server?
a piece of computer hardware or software that provides functionality for other programs or devices, called “clients”
Which HTTP method does a browser issue to a web server when you visit a URL?
GET
What three things are on the start-line of an HTTP request message?
HTTP method, request target (usually URL), HTTP version
What three things are on the start-line of an HTTP response message?
protocol version (usually HTTP/1.1), status code, status text
What are HTTP Headers?
They let the client and the server pass additional information with an HTTP request or response.
Where would you go if you wanted to learn more about a specific HTTP Header?
MDN
Is a body required for a valid HTTP request or response message?
no
What is AJAX?
It is a programming practice of building complex, dynamic webpages using a technology known as XMLHttpRequest.
What does the AJAX acronym stand for?
stands for Asynchronous JavaScript and XML
Which object is built into the browser for making HTTP requests in JavaScript?
XMLHttpRequest()
What event is fires by XMLHttpRequest objects when they are finished loading the dat from the server?
load
An XMLHttpRequest object has an addEventListener() method just like DOM elements. How is it possible that they both share this functionality?