JavaScript Syntax and Fundamentals

Variables, operators, control flow, functions, arrays and objects: enough JavaScript to make a page interactive.

Beginner · about 12 hours · difficulty 2/5

Learn first: HTML Document Essentials

JavaScript is the only programming language browsers run natively, which makes it the centre of frontend work. Learn the language itself before any framework; frameworks change, the language underneath stays.

Building blocks

  • Variables: use const by default, let when you must reassign, and avoid var (function-scoped and hoisted in confusing ways).
  • Primitive values: string, number, boolean, null, undefined, bigint, symbol. Everything else is an object (including arrays and functions).
  • Operators: arithmetic, comparison (always prefer === over ==), logical &&, ||, and the nullish ??.
  • Control flow: if/else, switch, for, for...of (values of an iterable), while, break/continue.
  • Functions: declarations, expressions and arrow functions; parameters with defaults; returning values.

Arrays and objects

Most real code is data transformation. Get fluent with map, filter, reduce, find, some, includes, sort (beware: it mutates and sorts strings by default) and object access with dot and bracket notation. Object.keys/values/entries let you loop over objects.

How to practise

Write small programs in the browser console or Node: a to-do list in memory, a word counter, a grade calculator. Read error messages carefully; they usually tell you the exact line and cause.

Good enough to move on

You can write a function that takes an array of objects (say, products) and returns a filtered, sorted, transformed result without looking up the syntax, and you can debug it with console.log and breakpoints.

Key concepts

  • const, let and var
  • Primitive types and objects
  • Operators and strict equality
  • Control flow and loops
  • Functions and arrow functions
  • Array methods: map, filter, reduce
  • Objects and property access
  • Strings and template literals
  • Debugging with console and breakpoints

Mini project

Build a command-line or console-based expense tracker: add, list, filter by category, and compute totals per month using only arrays, objects and array methods.

Check yourself

What is the difference between for...of and for...in, and which one should you use to loop over an array?

Free resources