Glassdoor Flashcards
If we wanted to implement a method of tracking every click that the user made on the site, how would we want to do this?
Place a JavaScript event listener for all clicks at the document level. Perform actions based on the details of the click. This problem had multiple branches and sub-questions, but the gist is that you would want to capture the events as they bubbled back up to the document level. There are other acceptable answers to this question.
Is there any difference between window and document?
Yes. JavaScript has a global object and everything runs under it. window is that global object that holds global variables, global functions, location, history everything is under it. Besides, setTimeout, ajax call (XMLHttpRequest), console or localStorage are part of window.
document is also under window. document is a property of the window object. document represents the DOM and DOM is the object oriented representation of the html markup you have written. All the nodes are part of document. Hence you can use getElementById or addEventListener on document. These methods are not present in the window object.
window.onload vs document.onload
window. onload is fired when DOM is ready and all the contents including images, css, scripts, sub-frames, etc. finished loaded. This means everything is loaded.
document. onload is fired when DOM (DOM tree built from markup code within the document)is ready which can be prior to images and other external content is loaded.
Think about the differences between window and document, this would be easier for you.
attribute vs property
attributes are just like attribute in your html tag (XML style attribute) inside the starting tag. html attributes are exposed to the DOM via property. Hence, a property is created when DOM is parsed for each attribute in the html tag. If you change an attribute only the value of the property will change. However, the value of attribute will remain same.
What are the different ways to get an element from DOM
You can use the following methods in document
getElementById to get a element that has the provided Id. getElementsByClassName to get a nodelist (nodelist is not an array, rather it is array-like object) by providing a class name. getElementsByTagName to get a nodelist by the provided tag name. querySelector you will pass css style selector (jquery style) and this will retrurn first matched element in the DOM. querySelectorAll will return a non-live nodelist by using depth-first pre order traversal of all the matched elements. Non-live means, any changes after selecting the elements will not be reflected. There are two more options but I dont use them frequently-
getElementsByName returns the list of elements by the provided name of the html tag
getElementsByTagNameNS returns elements with particular tag name within the provided namespace
What is the fastest way to select elements by using css selectors
It depends on what you are selecting. If you have an ID of an element getElmentById is the fastest way to select an element. However, you should not have so many ID in you document to avoid style repetition. css class getElementsByClassName is the second quickest way to select an element
Here is the list. As we go downwards through the list, it takes more time to select elements.
ID (#myID) Class (.myClass) Tag (div, p) Sibling (div+p, div~p) child (div>p) Descendant (div p) Universal (*) Attribute (input[type="checkbox"]) Pseudo (p:first-child) If you have crazy long selectors to select element, think about your selectors and check whether you can use a class instead
Are CSS property names case-sensitive?
No
Does setting margin-top and margin-bottom have an affect on an inline element?
No
Does setting padding-top and padding-bottom on an inline element add to its dimensions?
No
If you have a <p> element with font-size: 10rem, will the text be responsive when the user resizes / drags the browser window?</p>
Equal to the computed value of font-size on the root element. When specified on the font-size property of the root element, the rem units refer to the property’s initial value.
This means that 1rem equals the font size of the html element (which for most browsers has a default value of 16p
rem is also known as root em. While em is relative to the font-size of its nearest parent, rem is only relative to the root’s ( i.e. HTML’s ) font-size.
As per the question, the rem unit does not make the text responsive. The font-size always remains the same even if you resize or drag the browser
no
What is the order of presedence in css?
most to least specificity
style attribute (inline styling)
id
class, psuedo-class, attribute
elements
Are unused style resources still downloaded by the browser?
no
What is a protocal?
A way for two applications to speak to each other
What is a web resource?
Document hosted by a web server
HTML, PDF, JSON
can be static or dynamic
dynamic is one that generated on the fly
ex: a web application that tells the time
Does every web source have a unique URL?
Yes