Web Development Bootcamp Flashcards
Rule for coding #1: Trick Your Brain
with the 20 minute
Rule
What strategy can be used to harness inertia and form a consistent coding habit?
Upon transitioning (e.g., arriving home), start with a 20-minute coding goal to overcome task-switching resistance. Mark each successful day on a calendar, aiming to keep a continuous line unbroken to build a month-long habit.
What is the Internet essentially composed of?
The Internet is a network of wires connecting different computers worldwide.
What is the role of servers and clients in the context of the Internet?
Servers store and serve data/files for websites and are online 24/7. Clients, like personal computers, access this data via the Internet.
How does a DNS server function in the process of accessing a website?
A DNS (Domain Name System) server translates a website’s domain name (like Google.com) into its IP address, allowing the browser to request the website’s data directly from its server.
What is the significance of an IP address?
Every computer connected to the Internet has an IP address, which acts like a unique postal code, facilitating the sending and receiving of files/data.
How do continents remain interconnected on the Internet?
Continents are connected by massive undersea cables composed of fiber optic fibers, transmitting data using lasers at speeds up to 400 gigabytes per second.
Describe the basic flow of communication when accessing a website via a URL.
Upon entering a URL, the browser sends a request to the ISP (Internet Service Provider). The ISP queries a DNS server to get the IP address of the website. The DNS server responds with the IP address. The browser then directly requests the website’s data from the respective server using the IP address. The server sends back the necessary files and data to display the website, which the browser then renders for the user.
What are the three primary types of files that browsers use to render websites?
The three main file types are HTML, CSS, and JavaScript.
What is the purpose of the HTML code file in a website?
The HTML code file determines the content of a website, such as text, images, buttons, and links. It can be likened to the bricks of a house.
How does the CSS file contribute to the design of a website?
CSS files style the website by determining its appearance, such as colors, shapes, and fonts. It applies these styles to the content created using HTML.
The painting of a house, style.
What role does JavaScript play in a website?
JavaScript adds functionality to a website, turning it from a static page into an interactive platform. It allows users to perform actions like sending emails or making posts.
Electricity and gas and services.
How do the browser and the files from a server collaborate to display the Google homepage?
The browser uses the HTML from the server to display the content (e.g., logo, buttons, text box). The CSS files then style these components. Finally, the JavaScript provides the website’s functionality, such as searching.
What is the Chrome developer tools, and why is it useful?
The Chrome developer tools are a suite of web developer utilities integrated into the Chrome browser. They allow users to inspect and modify elements on a web page, aiding in debugging and website design.
Which browser dominated the 90s?
Netscape Navigator dominated the 90s.
Who was one of the principal makers of Netscape Navigator?
Marc Andreessen was one of the principal makers of Netscape Navigator.
Briefly summarize the history of web browsers.
Before modern browsers like Chrome, Firefox, or Safari, there was Mosaic. Marc Andreessen worked on Mosaic in university and later began work on Netscape. Netscape Navigator once held over 80% of the market share but lost the browser war to Internet Explorer. Its technology was later incorporated into Firefox.
What did websites in 1995 lack and how did they function?
In 1995, websites lacked dynamic, real-time functionality. If a website needed some action, the request was sent to the data server where computations occurred, and then a new page with the result was returned.
Who was contracted to create a new scripting language for web dynamics and interactivity?
Brendan Eich was contracted to create a new scripting language that became Javascript.
What is the impact of disabling Javascript in a browser?
Without Javascript, many websites will not load or function properly. For instance, Twitter will have a different design and YouTube or Netflix won’t load. Disabling Javascript can also lead to an ad-free browsing experience.
What was Javascript originally called and why did its name change?
Javascript was originally called Livescript. The name changed due to the popularity of the term “Java” in the 90s.
What is ECMAscript and its relevance to Javascript?
ECMAscript (European Computer Manufacturers Association Script) is a standardized version of Javascript. It is commonly referred to as ES followed by a version number (e.g., ES6, ES7).
Why is Javascript referred to as a scripting language and how does it relate to web development?
Just as scripts in plays instruct actors, scripting languages direct website elements. In web development, Javascript scripts instruct HTML elements, determining webpage behaviors and interactions.
How is Javascript different from Java?
Javascript and Java are fundamentally different. Javascript is an interpreted programming language while Java is a compiled language. They are as related as car is to carpet.
How is modern Javascript utilized and its significance in the web development world?
Modern Javascript is versatile and used in various frameworks from front end to back end. It’s the one language supported by all major browsers and powers the web, evidenced by its popularity in 2018 as a top programming language.
How can you practice JavaScript in browsers?
To practice JavaScript in browsers, navigate to View -> Developer -> JavaScript Console in Chrome.
How do you execute code in the JavaScript Console?
In the JavaScript Console, code runs as you hit ‘Enter’.
How can you create a pop-up in JavaScript?
To create a pop-up, use the ‘alert()’ function. Example: alert(‘Hello’);
How do you write multi-line code in the JavaScript Console without executing the current line?
For multi-line code in the console, hold ‘Shift’ + ‘Enter’ to go to the next line without executing the current line.
What tool in Chrome allows you to write and execute multi-line JavaScript code more easily than the Console?
Chrome’s ‘Snippets’ tool (under ‘Sources’ tab) allows you to write and execute multi-line JavaScript code more easily than the Console.
What are keywords in JavaScript?
Keywords in JavaScript (like ‘alert’) are predefined and have special meaning. They can’t be replaced with arbitrary words.
What will the browser do if you use an undefined keyword in your code?
If you use an undefined keyword in your code, the browser will throw a ‘ReferenceError’.
Where can you refer to understand JavaScript keywords and methods?
To understand JavaScript keywords and methods, refer to MDN Web Docs.
What is JavaScript syntax?
JavaScript has a specific syntax which includes the use of semi-colons to end instructions, and quotation marks to denote strings.
Why should you be cautious of using quotation marks from word processors in your JavaScript code?
Be cautious of using quotation marks from word processors in your code. In programming, opening and closing quotation marks are the same symbol.
What is the style convention regarding spaces in JavaScript?
Avoid unnecessary spaces between keywords, parentheses, and semi-colons in your code for uniformity and readability.
What is the style convention regarding quotation marks in JavaScript?
While both single and double quotes can denote strings, using double quotes is a common convention in JavaScript.
Where can you find best practices for writing JavaScript?
For best practices in writing JavaScript, refer to the AirBnB JavaScript Style Guide.
Why is consistency important in a codebase?
It’s essential for a codebase to look as if a single person wrote it, regardless of how many contributors there were. This ensures consistency and readability.
How do you get the length of a string in javascript
varName.length
How do I slice strings in javascript?
myString.slice(x,y)
How do I know the length of a string in javascript?
myString.length
How do I change a string to uppercase and lowercase?
myString.toUpperCase();
myString.toLowerCase();
How do you show an alert in javascript?
alert(“Message”);
What does the prompt(“message”); function does?
It shows a prompt (similar to an alert) and asks for a string entry that we can store in a variable.
In javascript, what’s the difference between == and ===?
Double comparator only compares the value, not the type so 1 == “1” -> true. Triple comparator also compares the type, so 1 === “1” -> false
How do I know if an array includes an element?
myArray.includes(<searched_element>);</searched_element>
what does the myArray.pop() function do?
Takes out an element at the end of the array
what does the myArray.push(element) do?
Adds element to the end of the array
In JavaScript, what does the getElementsByTagName function do and how is it used?
getElementsByTagName is a method of the Document object. It returns a live HTMLCollection of elements with the given tag name.
Usage:
javascript
var paragraphs = document.getElementsByTagName(‘p’);
// This will return all the <p> elements in the document.
Note: The returned collection is live, meaning it will update if new elements with the specified tag are added to the document.
In JavaScript, what does the getElementsByClassName function do and how is it used?
The getElementsByClassName is a method of the Document object. It returns a live HTMLCollection of elements with the given class name.
Usage:
var activeItems = document.getElementsByClassName(‘active’);
// This will return all the elements with the class “active”.
Note: The returned collection is live, meaning it will update if new elements with the specified class are added to the document or if the class attribute of existing elements changes.
In JavaScript, what does the getElementById function do and how is it used?
The getElementById is a method of the Document object. It retrieves the first element in the document with the specified id attribute.
Usage:
var myElement = document.getElementById(‘uniqueId’);
// This will return the element with the ID “uniqueId”.
Note: Element IDs should be unique within a document. If there are multiple elements with the same ID, it will return the first one it encounters.
In JavaScript, what does the querySelector function do and how is it used?
The querySelector is a method of the Document object. It retrieves the first element in the document that matches a specified CSS selector.
Usage:
var myElement = document.querySelector(‘.myClass’);
// This will return the first element with the class “myClass”.
var myDiv = document.querySelector(‘#myId div.someClass’);
// This will return the first “div” element with class “someClass” inside the element with the ID “myId”.
Note: Unlike getElementById or getElementsByClassName, querySelector allows for more complex and versatile queries using full CSS selector syntax. If no matches are found, it returns null.
What are the basic rules for selecting elements using CSS selectors in JavaScript, particularly for selecting by ID, class, and other common attributes?
By ID: Use the hash (#) symbol followed by the ID value.
“#myId” /* Selects an element with the ID of “myId” */
By Class: Use a dot (.) followed by the class name.
.myClass /* Selects all elements with the class “myClass” */
By Element Type: Simply use the name of the element.
p /* Selects all <p> elements */
By Attribute: Use square brackets and the attribute name, optionally with a value.
[data-attribute] /* Selects all elements with the "data-attribute" attribute */ [data-attribute="value"] /* Selects elements with a "data-attribute" of "value" */
You can combine selectors to create more specific queries:
div.myClass#myId[data-attribute=”value”] /* Selects a <div> element with class “myClass”, ID “myId”, and a “data-attribute” of “value” */
Note: These rules apply for both stylesheets and when using methods like querySelector in JavaScript.
How can you use hierarchical CSS selectors to target elements based on their relationship and nesting within the HTML structure?
Descendant Selector: Selects all elements that are descendants of a specified element.
article p
/* Selects all <p> elements inside an <article> element, regardless of how deeply nested they are */
Child Selector: Targets elements that are direct children of a specific element.
article > p
/* Selects only <p> elements that are direct children of an <article> element, but not those nested deeper */
Adjacent Sibling Selector: Selects an element that is directly after another specific element, and both share the same parent.
h2 + p
/* Selects the first <p> element immediately following any <h2> */
General Sibling Selector: Targets elements that share the same parent and appear after a specific element.
h2 ~ p /* Selects all <p> elements that follow an <h2> and share the same parent, not just the immediate sibling */
You can combine these hierarchical selectors with other selectors (e.g., by ID, class) to create more specific and complex queries.
What happens when you use querySelector and the query matches more than one element?
You get only the first element
How do I get all the elements matching a particular query with querySelector()
You can’t, you must use querySelectorAll() for that.
How do we access “css” properties when using querySelector? Are their names the same?
No, we use exactly the same name but camel cased instead of using intermediate dashes.
In css: how do we specify the property values composed of more than one string element?
Always as strings, e.g.
- padding: 7% 15p;
- becomes: style.padding = “7% 15p”;
What would be the ideal separation of concerns in a website?
styles -> only in css
content -> only in html
behavior -> only in javascript
what does querySelector(“button”).classList
Returns an array with the list of classes the button element has
How can we manipulate element styles from javascript while keeping all the style code in css files?
By having css classes and dynamically add/remove them with javascript
what does classList.toggle(“class-name”);
Toggles the specified class on and off the selected element
What document.querySelector(“h1”).innerHTML;
Returns the whole html inside the selected element. Allows to get and set (by using an =)
What does document.querySelector(“h1”).textContent;
Gets only the text inside the element. Allows to get or set. document.querySelector(“h1”).textContet= “hi”;
How do we get the value of an html attribute?
document.querySelector(“element”).getAttribute(“attrName”);
How do we set the value of an html attribute?
document.querySelector(“element).setAttribute(“attrName”, “attrVal”);
How do we add event listeners to html elements?
document.querySelectorAll(“<selector>").addEventListener("event name", function () {
alert("I got clicked!"+ i);
});</selector>
how do I open the debugger mode in the chrome console?
By typing debugguer; and click ctrl + enter
What is the this keyword in JavaScript and how does it behave?
The this keyword in JavaScript is a special variable that takes the value of the object it is directly invoked within. It is a context-specific reference that changes depending on how a function is called
How should we name constructors in javascript?
Capitalized
What does the following code do?
function BellBoy(name, age){
this.name = name
this.age = age
}
var bellBoy1 = new BellBoy(“timmy”, 19);
It uses the BellBoy “constructor” to create a new BellBoy object by using the provided parameters to initialize the bell boy fields.
Notice that we use the reserved word “new” before calling the constructor.
What is other name for constructors?
Factories
What does CSS stand for?
Cascading Style Sheet
What are the three ways of adding css?
- inline: in the element itself through the “style” attribute. useful for a single element
- internal: through the <style>//css</style> tag. using for a single file
- external: through an external file and then using a <link></link> element with rel=”stylesheet” and href=”location/styles.css”