Reader small image

You're reading from  Hands-on JavaScript for Python Developers

Product typeBook
Published inSep 2020
Reading LevelIntermediate
PublisherPackt
ISBN-139781838648121
Edition1st Edition
Tools
Right arrow
Author (1)
Sonyl Nagale
Sonyl Nagale
author image
Sonyl Nagale

Chicago-born, Iowa-raised, Los Angeles-seasoned, and now New York City-flavored, Sonyl Nagale started his career as a graphic designer focusing on web, which led down the slippery slope to becoming a full-stack technologist instead. With an eye toward the client use case and conversation with the creative side, he prides himself on taking a holistic approach to software engineering. Having worked at start-ups and global media companies using a variety of languages and frameworks, he likes solving new and novel challenges. Passionate about education, he's always excited to have great teachable moments complete with laughter and seeing the Aha! moments in students eyes.
Read more about Sonyl Nagale

Right arrow

Chapter 1

  1. What international group maintains the official specification for JavaScript?
    1. W3C
    2. Ecma International
    3. Netscape
    4. Sun
  2. Which backends can communicate with JavaScript?
    1. PHP
    2. Python
    3. Java
    4. All of the above
  3. Who was the original author of JavaScript?
    1. Tim Berners-Lee
    2. Brendan Eich
    3. Linus Torvalds
    4. Bill Gates
  4. What is the DOM?
    1. JavaScript's representation of HTML in memory
    2. An API to allow JavaScript to modify the page
    3. Both of the above
    4. None of the above
  5. What is the primary use of Ajax?
    1. Communication with the DOM
    2. Manipulation of the DOM
    3. Listening for user input
    4. Communication with a backend

Chapter 2

  1. True or false: Node.js is single-threaded.
  2. True or false: The architecture of Node.js makes it impervious to Distributed Denial of Service (DDoS) attacks.
  3. Who originally created Node.js?
    1. Brendan Eich
    2. Linux Torvalds
    3. Ada Lovelace
    4. Ryan Dahl
  4. True or false: JavaScript on the server side is inherently insecure because the code is exposed on the frontend.
  5. True or false: Node.js is inherently superior to Python.

Chapter 3

  1. Which of these is not a valid JavaScript variable declaration?
    1. var myVar = 'hello';
    2. const myVar = "hello"
    3. String myVar = "hello";
    4. let myVar = "hello"
  2. Which of these starts a function declaration?
    1. function
    2. const
    3. func
    4. def
  3. Which of these is not a basic loop type?
    1. for..in
    2. for
    3. while
    4. map
  4. JavaScript requires line delineation with semicolons:
    1. True
    2. False
  1. Whitespace never counts in JavaScript:
    1. True
    2. False

Chapter 4

  1. JavaScript is inherently:
    1. Synchronous
    2. Asynchronous
    3. Both
  2. A fetch() call returns a:
    1. then
    2. next
    3. finally
    4. Promise
  3. With prototypal inheritance, we can (select all options that apply):
    1. Add methods to a base data type.
    2. Subtract methods from a base data type.
    3. Rename our data type.
    4. Cast our data into another format.
let x = !!1
console.log(x)
  1. Given the preceding code, what will be the expected output?
    1. 1
    2. false
    3. 0
    4. 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")
  1. Given this code, what's the best way to output "Will Riker"?
    1. Riker.sayHello() *
    2. console.log(Riker.name)
    3. console.log(Riker.this.name)
    4. 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
}
  1. How would you get an alert of 'Hello Bob'?
    1. sayHello()('Bob')
    2. sayHello('Bob')()*
    3. sayHello('Bob')
    4. someFunc()(sayHello('Bob'))
  2. What will alert(greeting) do in the preceding code?
    1. Alert 'greeting'
    2. Alert 'Hello Alice'
    3. Throw an error
    4. None of the above
  3. How would we get an alert message of 1?
    1. someFunc()()*
    2. sayHello().sayZip()
    3. alert(someFunc.bar)
    4. sayZip()
  4. How would we get an alert message of 2?
    1. someFunc().foo()
    2. someFunc()().beep
    3. We can't, because it's not in scope
    4. We can't, because it's not defined
  5. How can...

Chapter 6

Consider the following code:

  <button>Click me!</button>
  1. What is the correct syntax to select the button?
    1. document.querySelector('Click me!')
    2. document.querySelector('.button')
    3. document.querySelector('#button')
    4. 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>
  1. True or False: document.querySelector('button') will serve our needs to place a click handler on each button.
  2. To change the text of the button from "Click me!" to "Click me first!", what should we use?
    1. document.querySelectorAll('button')[0].innerHTML = "Click me first!"
    2. document.querySelector('button')[0].innerHTML = "Click me first!"
    3. document.querySelector('button').innerHTML = "Click me first!"
    4. document...

Chapter 7

Answer the following questions to gauge your understanding of events:

  1. Which of these is the second phase of the event lifecycle?
    1. Capturing
    2. Targeting
    3. Bubbling
  2. (Choose all the correct answers) What does the event object provide us with?
    1. The type of event that is triggered
    2. The target DOM node, if applicable
    3. The mouse coordinates, if applicable
    4. 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()
})
}
})
  1. Which JavaScript features is it using? Select all the answers that apply...

Chapter 9

  1. What is the root cause of memory problems?
    1. The variables in your program are global.
    2. Inefficient code.
    3. JavaScript's performance limitations.
    4. Hardware inadequacies.
  1. When using DOM elements, you should store references to them locally versus always accessing the DOM.
    1. True
    2. False
    3. True when using them more than once
  2. JavaScript is pre-processed on the server side, and thus more efficient than Python.
    1. True
    2. False
  3. Setting breakpoints can't find memory leaks.
    1. True
    2. False
  4. It's a good idea to store all variables in the global namespace as they're more efficient to reference.
    1. True
    2. False
lock icon
The rest of the chapter is locked
You have been reading a chapter from
Hands-on JavaScript for Python Developers
Published in: Sep 2020Publisher: PacktISBN-13: 9781838648121
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

Author (1)

author image
Sonyl Nagale

Chicago-born, Iowa-raised, Los Angeles-seasoned, and now New York City-flavored, Sonyl Nagale started his career as a graphic designer focusing on web, which led down the slippery slope to becoming a full-stack technologist instead. With an eye toward the client use case and conversation with the creative side, he prides himself on taking a holistic approach to software engineering. Having worked at start-ups and global media companies using a variety of languages and frameworks, he likes solving new and novel challenges. Passionate about education, he's always excited to have great teachable moments complete with laughter and seeing the Aha! moments in students eyes.
Read more about Sonyl Nagale