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.


nothing but the usual


atomic types


atomic types (continued)


boolean operators

the syntax for boolean operators is here again inherited from C / C++ / Java:

and: &&

or: ||

not: !


strings

litteral string:
very much alike Python - can use single or double quotes

formatted string:
remember the equivalent of f-strings is `made with ${expression} inside backticks`


arrays


common operations on arrays


searching in array


for .. of: iterating over values


for .. in: iterating over indices

this is a little bit like when using enumerate() in Python

  • using for .. in iterates over indices but wait, it can behave oddly...


other stuff on arrays


shared references (advanced)


pythontutor illustration


args are passed by reference (advanced)


arguments passing is loosely checked


more on arguments (advanced)


hash-based data types

see also


objects


class instances are objects

the class construct allows to name your own type
and instances of that type are objects just like the previous example


examples


more examples


iteration over object keys

several options; probably the safest is

or to iterate over keys only


unpacking objects (reminder)

this is also known as deconstructing / reconstructing
and these are truly all over the place in modern JavaScript code

unpacking an array


unpacking an object

there is a similar destructuring assignment on objects


object as optional parameters

the parameter-passing mechanism is not as powerful as Python
but here’s a common pattern to define optional parameters with default values


console.log() and objects

TIP about debugging JS objects :


accessing object keys (advanced)

a reminder too:


Wat ?

And now for a bit of fun: the famous “Wat” lightning talk by Gary Bernhardt is a must-watch for JavaScript programmers