Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.


preamble

also remember that we focus on the browser runtime here
refer to this screenshot to spot the browser console


console.log() function

see also below how to format strings with backticks a la Python f-strings


syntax

tests and loops


== vs ===

talking of tests, a common pitfall for newcomers is the difference between == and ===[2]


C-style for loop


switch

the switch statement in JavaScript is similar to the ones in C++ and Java
it will branch your control flow into a location that depends on the subject’s value

do not forget the break statements !


variables

declaration


Python-style unpacking


object unpacking

anticipating a bit, but there’s a very handy construction that looks a bit like the one above


variable scope


blocks {} and scope illustrated

the elementary unit for scope is the block - which is materialized by {}


do not use var !


globals

context (browser components mostly) is exposed to programer through a set of global variables, e.g.


formatting with backticks

in JS, the backticks `` feature reminds of Python’s f-strings


functions

like in other languages, and we have seen examples already


loose parameter binding


duck typing

like in Python, objects are typed, but variables are not bound to a given type


this


exceptions

JavaScript supports exceptions, just like Python, with the same bubbling mechanism
that scans the call stack until a catch statement is found


classes

as of ES2015, the language has a proper class statement


notes on classes

NOTICE the following facts from that first class example :


get / set (advanced)


Footnotes
  1. being a Pythonist at heart, I prefer omitting semicolons whenever possible; this is not a very widespread practice though if I’m being honest

  2. this resonates a bit, but not quite exactly, with Python that has == and is to compare values vs identities