Book Image

Hands-on JavaScript for Python Developers

By : Sonyl Nagale
Book Image

Hands-on JavaScript for Python Developers

By: Sonyl Nagale

Overview of this book

Knowledge of Python is a great foundation for learning other languages. This book will help you advance in your software engineering career by leveraging your Python programming skills to learn JavaScript and apply its unique features not only for frontend web development but also for streamlining work on the backend. Starting with the basics of JavaScript, you’ll cover its syntax, its use in the browser, and its frameworks and libraries. From working with user interactions and ingesting data from APIs through to creating APIs with Node.js, this book will help you get up and running with JavaScript using hands-on exercises, code snippets, and detailed descriptions of JavaScript implementation and benefits. To understand the use of JavaScript in the backend, you’ll explore Node.js and discover how it communicates with databases. As you advance, you’ll get to grips with creating your own RESTful APIs and connecting the frontend and backend for holistic full-stack development knowledge. By the end of this Python JavaScript book, you’ll have the knowledge you need to write full-fledged web applications from start to finish. You’ll have also gained hands-on experience of working through several projects, which will help you advance in your career as a JavaScript developer.
Table of Contents (26 chapters)
Section 1 - What is JavaScript? What is it not?
Section 2 - Using JavaScript on the Front-End
Section 3 - The Back-End: Node.js vs. Python
Section 4 - Communicating with Databases

Wiring your API together

To further understand the gameplay, we'll walk through the steps involved in firing a torpedo from a ship:

  1. Locate the frontend JavaScript in public/javascripts/play.js:
document.querySelectorAll('.fire').forEach((el) => {
el.addEventListener('click', (e) => {
const weapon = ('fire-torpedo')
> 0) ? "torpedo" : "phasers"
const target =
  1. Here we've made a click handler on the fire buttons in our interface and identified our weapon and target ship:
`/play/fire? attacker=${'td').dataset.attacker}&target=${target}&weapon=${weapon}`)
.then(response => response.json())
.then(data => {

This line might take a bit of unpacking. We're making an AJAX call to our Node application from our JavaScript with certain query string parameters: attacker...