Key Concepts

Review core concepts you need to learn to master this subject


JavaScript is a popular web-based programming language that powers the dynamic behavior on most websites. Alongside HTML and CSS, it is a core technology that makes the web run.

JavaScript Methods

Methods return information about an instance of data, and are called by appending an instance with a period (.), the method name, and parentheses.

JavaScript Libraries

JavaScript libraries contain methods that you can call by appending the library name with a period (.), the method name, and a set of parentheses.


The console.log() method is used to log or print text to the console. It can also be used to print objects, arrays, and other info. This makes it a useful tool for debugging JavaScript.

JavaScript Numbers

Numbers are a primitive data type, one of the most basic data types available within the JavaScript language. They include the set of all integers and floating point numbers.


The length property of a string returns the number of characters that make up the string.

Data Instances in JavaScript

When you introduce a new piece of data into a JavaScript program, the program keeps track of it in an instance of that data type. An instance is an individual case of a data type.


Booleans are a primitive data type, one of the most basic types in JavaScript. They can be either true or false. Use Boolean() to evaluate the truth value.


Math.random() returns a floating-point, random number in the range from 0 inclusive up to but not including 1.

JavaScript Math.floor()

The Math.floor() function in JavaScript returns the largest integer less than or equal to the given number. In the above example , console.log(Math.floor(number)) will log 15 in console when the number variable is set to the value 15.95 .

Single Line Comments

In JavaScript, single-line comments are made with two consecutive forward slashes (//).

JavaScript Null

Null is a primitive data type, one of the most basic data types available within the JavaScript language. It represents the intentional absence of value. In code, it is represented as null.

JavaScript Strings

Strings are a primitive data type. They are any grouping of characters (letters, spaces, numbers, or symbols) surrounded by single quotes or double quotes.

JavaScript Arithmetic Operators

JavaScript supports the basic arithmetic operators for addition (+), subtraction (-), multiplication (*), and division (/).

Multi-line comments in JavaScript

Multi-line comments are made by surrounding the lines with /* at the beginning and */ at the end . Comments are good ways for variety of reasons like explaining a code block or indicating some hints etc.

Mathematical assignment operators in JavaScript

In JavaScript, the addition assignment operator (+=) can be used to add the value on the right hand side to the existing value & assign it to the variable. The addition assignment operator is a shorthand for variableName = variableName + value. Subtraction assignment (-=), multiplication assignment (*=) & division assignment (/=) perform similar operations.

JavaScript String Interpolation

String interpolation is the process of evaluating string literals containing one or more placeholders (expressions, variables, etc). The two main ways to interpolate strings are with string concatenation (syntax: "string" + expression + "string") or template literals (syntax: `text ${expression} text`).

Usage of variables in JavaScript

Variables are used whenever there’s a need to store a piece of data. A variable contains data that can be used in the program elsewhere. Using variables also ensures code re-usability since it can be used to replace same value in multiple places.

JavaScript: undefined

undefined is a primitive JavaScript value that represents lack of defined value. Variables that are declared but not initialized to a value will have the value undefined.

JavaScript variables

Whenever there’s a need to use a piece of data, variables are a good solution. A variable contains data that can be used in the program. For instance, if a certain code block is written to check the age, the value to be compared can be assigned in a variable. The best practice for JavaScript variables is to give them names that identify their use.

Declaring variables using var, let & const in JavaScript

To declare a variable in JavaScript, any of these three keywords - var, let or const can be used along with a variable name.

JavaScript Template literals

In JavaScript, template literals are strings that allow embedded expressions (${expression}). While regular strings use single (') or double (") quotes, template literals use backticks instead. Take a look at the code block above to see examples.

JavaScript let variable values

let creates a local variable in JavaScript & can be re-assigned. Initialization during the declaration of a let variable is optional. A let variable will contain undefined if nothing is assigned to it.

const keyword in JavaScript

A constant variable can be declared using the keyword const. In the code block, a const named numberOfColumns has been assigned the value 4. It is a one-time assignment . Any attempt of re-assigning a const variable will result in JavaScript runtime error: TypeError: Assignment to constant variable. Variables defined with the keyword const must be assigned values during declaration.

String concatenation in JavaScript

In JavaScript, multiple strings can be concatenated together using the + operator. In the example, multiple strings and variables containing string values have been concatenated. After execution of the code block, the displayText variable will contain the concatenated string.

Chevron Left Icon
Introduction to JavaScript
Lesson 1 of 2
Chevron Right Icon
  1. 1
    Last year, millions of learners from our community started with JavaScript. Why? JavaScript is primarily known as the language of most modern web browsers, and its early quirks gave it a bit of a b…
  2. 2
    The console is a panel that displays important messages, like errors, for developers. Much of the work the computer does with our code is invisible to us by default. If we want to see things appear…
  3. 3
    Programming is often highly collaborative. In addition, our own code can quickly become difficult to understand when we return to it— sometimes only an hour later! For these reasons, it’s oft…
  4. 4
    Data types are the classifications we give to the different kinds of data that we use in programming. In JavaScript, there are seven fundamental data types: 1. Number: Any number, including nu…
  5. 5
    Basic arithmetic often comes in handy when programming. An operator is a character that performs a task in our code. JavaScript has several built-in in arithmetic operators, that allow us to …
  6. 6
    Operators aren’t just for numbers! When a + operator is used on two strings, it appends the right string to the left string: console.log(‘hi’ + ‘ya’); // Prints ‘hiya’ console.log(‘wo’ + ‘ah’); /…
  7. 7
    When you introduce a new piece of data into a JavaScript program, the browser saves it as an instance of the data type. Every string instance has a property called length that stores the number of…
  8. 8
    Remember that methods are actions we can perform. JavaScript provides a number of string methods. We call, or use, these methods by appending an instance with a period (the dot operator), the na…
  9. 9
    In addition to console, there are other objects built into JavaScript . Down the line, you’ll build your own objects, but for now these “built-in” objects are full of useful functionality. For e…
  10. 10
    Let’s take one more glance at the concepts we just learned: - Data is printed, or logged, to the console, a panel that displays messages, with console.log(). - You can write single-line comments w…
  1. 1
    In programming, a variable is a container for a value. You can think of variables as little containers for information that live in a computer’s memory. Information stored in variables, such as a…
  2. 2
    There were a lot of changes introduced in the ES6 version of JavaScript in 2015. One of the biggest changes was two new keywords, let and const, to create, or declare, variables. Prior to the ES6…
  3. 3
    As mentioned in the previous exercise, the let keyword was introduced in ES6. The let keyword signals that the variable can be reassigned a different value. Take a look at the example: let meal = …
  4. 4
    The const keyword was also introduced in ES6, and is short for the word constant. Just like with var and let you can store any value in a const variable. The way you declare a const variable and as…
  5. 5
    Let’s consider how we can use variables and math operators to calculate new values and assign them to a variable. Check out the example below: let w = 4; w = w + 1; console.log(w); // Output: 5 …
  6. 6
    Other mathematical assignment operators include the increment operator (++) and decrement operator (–). The increment operator will increase the value of the variable by 1. The decrement ope…
  7. 7
    In previous exercises, we assigned strings to variables. Now, let’s go over how to connect, or concatenate, strings in variables. The + operator can be used to combine two string values even if th…
  8. 8
    In the ES6 version of JavaScript, we can insert, or interpolate, variables into strings using template literals. Check out the following example where a template literal is used to log strings …
  9. 9
    While writing code, it can be useful to keep track of the data types of the variables in your program. If you need to check the data type of a variable’s value, you can use the typeof operator. T…
  10. 10
    Nice work! This lesson introduced you to variables, a powerful concept you will use in all your future programming endeavors. Let’s review what we learned: * Variables hold reusable data in a pro…

What you'll create

Portfolio projects that showcase your new skills

Pro Logo

How you'll master it

Stress-test your knowledge with quizzes that help commit syntax to memory

Pro Logo