- What international group maintains the official specification for JavaScript?
- W3C
- Ecma International
- Netscape
- Sun
- Which backends can communicate with JavaScript?
- PHP
- Python
- Java
- All of the above
- Who was the original author of JavaScript?
- Tim Berners-Lee
- Brendan Eich
- Linus Torvalds
- Bill Gates
- What is the DOM?
- JavaScript's representation of HTML in memory
- An API to allow JavaScript to modify the page
- Both of the above
- None of the above
- What is the primary use of Ajax?
- Communication with the DOM
- Manipulation of the DOM
- Listening for user input
- Communication with a backend
You're reading from Hands-on JavaScript for Python Developers
Chapter 2
- True or false: Node.js is single-threaded.
- True or false: The architecture of Node.js makes it impervious to Distributed Denial of Service (DDoS) attacks.
- Who originally created Node.js?
- Brendan Eich
- Linux Torvalds
- Ada Lovelace
- Ryan Dahl
- True or false: JavaScript on the server side is inherently insecure because the code is exposed on the frontend.
- True or false: Node.js is inherently superior to Python.
Chapter 3
- Which of these is not a valid JavaScript variable declaration?
- var myVar = 'hello';
- const myVar = "hello"
- String myVar = "hello";
- let myVar = "hello"
- Which of these starts a function declaration?
- function
- const
- func
- def
- Which of these is not a basic loop type?
- for..in
- for
- while
- map
- JavaScript requires line delineation with semicolons:
- True
- False
- Whitespace never counts in JavaScript:
- True
- False
Chapter 4
- JavaScript is inherently:
- Synchronous
- Asynchronous
- Both
- A fetch() call returns a:
- then
- next
- finally
- Promise
- With prototypal inheritance, we can (select all options that apply):
- Add methods to a base data type.
- Subtract methods from a base data type.
- Rename our data type.
- Cast our data into another format.
let x = !!1
console.log(x)
- Given the preceding code, what will be the expected output?
- 1
- false
- 0
- true
const Officer = function(name, rank, posting) {
this.name = name
this.rank = rank
this.posting = posting
this.sayHello = () => {
console.log(this.name)
}
}
const Riker = new Officer("Will Riker", "Commander", "U.S.S. Enterprise")
- Given this code, what's the best way to output "Will Riker"?
- Riker.sayHello() *
- console.log(Riker.name)
- console.log(Riker.this.name)
- Officer.Riker.name()
Chapter 5
Consider the following code:
function someFunc() {
let bar = 1;
function zip() {
alert(bar); // 1
let beep = 2;
function foo() {
alert(bar); // 1
alert(beep); // 2
}
}
return zip
}
function sayHello(name) {
const sayAlert = function() {
alert(greeting)
}
const sayZip = function() {
someFunc.zip()
}
let greeting = `Hello ${name}`
return sayAlert
}
- How would you get an alert of 'Hello Bob'?
- sayHello()('Bob')
- sayHello('Bob')()*
- sayHello('Bob')
- someFunc()(sayHello('Bob'))
- What will alert(greeting) do in the preceding code?
- Alert 'greeting'
- Alert 'Hello Alice'
- Throw an error
- None of the above
- How would we get an alert message of 1?
- someFunc()()*
- sayHello().sayZip()
- alert(someFunc.bar)
- sayZip()
- How would we get an alert message of 2?
- someFunc().foo()
- someFunc()().beep
- We can't, because it's not in scope
- We can't, because it's not defined
- How can...
Chapter 6
Consider the following code:
<button>Click me!</button>
- What is the correct syntax to select the button?
- document.querySelector('Click me!')
- document.querySelector('.button')
- document.querySelector('#button')
- document.querySelector('button')
Take a look at this code:
<button>Click me!</button>
<button>Click me two!</button>
<button>Click me three!</button>
<button>Click me four!</button>
- True or False: document.querySelector('button') will serve our needs to place a click handler on each button.
- To change the text of the button from "Click me!" to "Click me first!", what should we use?
- document.querySelectorAll('button')[0].innerHTML = "Click me first!"
- document.querySelector('button')[0].innerHTML = "Click me first!"
- document.querySelector('button').innerHTML = "Click me first!"
- document...
Chapter 7
Answer the following questions to gauge your understanding of events:
- Which of these is the second phase of the event lifecycle?
- Capturing
- Targeting
- Bubbling
- (Choose all the correct answers) What does the event object provide us with?
- The type of event that is triggered
- The target DOM node, if applicable
- The mouse coordinates, if applicable
- The parent DOM node, if applicable
Look at this code:
container.addEventListener('click', (e) => {
if (e.target.className === 'box') {
document.querySelector('#color').innerHTML = e.target.style.backgroundColor
document.querySelector('#message').innerHTML = e.target.innerHTML
messageBox.style.visibility = 'visible'
document.querySelector('#delete').addEventListener('click', (event) => {
messageBox.style.visibility = 'hidden'
e.target.remove()
})
}
})
- Which JavaScript features is it using? Select all the answers that apply...
Chapter 9
- What is the root cause of memory problems?
- The variables in your program are global.
- Inefficient code.
- JavaScript's performance limitations.
- Hardware inadequacies.
- When using DOM elements, you should store references to them locally versus always accessing the DOM.
- True
- False
- True when using them more than once
- JavaScript is pre-processed on the server side, and thus more efficient than Python.
- True
- False
- Setting breakpoints can't find memory leaks.
- True
- False
- It's a good idea to store all variables in the global namespace as they're more efficient to reference.
- True
- False
The rest of the chapter is locked
You have been reading a chapter from
Hands-on JavaScript for Python DevelopersPublished in: Sep 2020Publisher: PacktISBN-13: 9781838648121
© 2020 Packt Publishing Limited All Rights Reserved
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime