JS behind the scenes Flashcards
What is the DOM?
The DOM stands for the Document Object Model. It is the structured representation of a HTML document and is used to connect webpages to scripts like those used in JS.
Is the DOM apart of JS?
No the DOM is not apart of JS. JS and the DOM are two separate things that interact.
How do we select HTML elements in JS?
We can select HTML elements by using the document.queryselector method. It uses the form: var x = document.getElementById("myDiv"); x.querySelector("p").innerHTML = "Hello World!";
The above selects the HTML element paragraph(‘p’) from the CSS element x which in this case is a Div.
What is MEAN and MERN stack development and what does each component responsible for?
MEAN and MERN stack development are a group of technologies that interact using JS to make a comprehensive application.
M - MongoDB makes use of JS to connect to a database providing the back end.
E - ExpressJS is a framework for nodeJS that helps handle client side server request.
A - Angular is a frontend framework that allows us to load one page in our browser that handles the entire website.
R - React is a JS library that allows us to build interactive UIs by loading certain components at a time.
N - node.JS is a runtime environment for JS that allows you to build applications without needing a browser.
What do we need to add to code so that it can react to events such as a ‘click’?
You must add an event listener. Event listeners are pieces of code that are attached to components in HTML or CSS that wait for a specific event to happen involving that component and execute a function.
What is a modal window?
A modal window is a window that appears as an overlay.
Using code, how can we add the ‘hidden’ property to an element called ‘modal’?
We can use the code:
modal.classList.add(‘hidden’);
How would I code an event listener that listens for a keypress on a modal element and performs function DoThis with argument x?
modal.addEventListener(‘keydown’, DoThis(x)
{ };
Write a piece of code that dynamically changes the src of an element called ‘diceEl’ to a pictures (named dice-x.png) of the result that corresponds to the dice roll variable dice_roll?
To dynamically change the picture in diceEl associated with the dice roll result stored in dice_roll you would use.
diceEl.src = dice-${dice_roll}.png
;
Is JS low-level?
No JS is high-level as it automatically manages a computers hardware resources for us.
Give an example of a programming paradigm and why is JS multi-paradigm?
Functional programming or Object-Oriented programming are examples of programming paradigms. JS uses a multiparadigm approach because you can use FP, OOP and Procedural programming with it.
Does JS use classes and instances?
No. JS is a prototype based language. It uses objects and these objects can be used as the template for new objects or specify their own object properties.
Can JS pass functions into other functions?
Yes. Functions in JS are treated as variables which means we can return them and pass them to other functions. The eventListener is a good example of this.
Is JS strongly typed?
No JS uses type coercion so it will try to distinguish each variables datatype at runtime.
What feature makes JS non-blocking?
The event loop allows JS to take long running tasks and run them on a separate thread in the background while other tasks are executed. Then once they are finished it moves them back through the main thread. This means that JS is non-blocking.