Key Concepts

Review core concepts you need to learn to master this subject

JavaScript

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.

Console.log()

The console.log() method is used to log or print messages to the console. It can also be used to print objects and other info.

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 Numbers

Numbers are a primitive data type. They include the set of all integers and floating point numbers.

JavaScript Booleans

Booleans are a primitive data type. They can be either true or false.

JavaScript Null

Null is a primitive data type. It represents the intentional absence of value. In code, it is represented as null.

Arithmetic Operators

JavaScript supports arithmetic operators for:

  • + addition
  • - subtraction
  • * multiplication
  • / division
  • % modulo

String.length

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

JavaScript Methods

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

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.

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.

Math.random()

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

Math.floor()

The Math.floor() function returns the largest integer less than or equal to the given number.

Single Line Comments

In JavaScript, single-line comments are created with two consecutive forward slashes //.

Multi-line Comments

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

const Keyword

A constant variable can be declared using the keyword const. It must have an assignment. Any attempt of re-assigning a const variable will result in JavaScript runtime error.

let Keyword

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.

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.

Assignment Operators

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. Here are all of them:

  • += addition assignment
  • -= Subtraction assignment
  • *= multiplication assignment
  • /= division assignment

JavaScript String Concatenation

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.

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: "string" + expression + "string"
  • Template literals: `text ${expression} text`

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 for examples.

JavaScript Variables

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 the same value in multiple places.

Declaring Variables

To declare a variable in JavaScript, any of these three keywords can be used along with a variable name:

  • var is used in pre-ES6 versions of JavaScript.
  • let is the preferred way to declare a variable when it can be reassigned.
  • const is the preferred way to declare a variable with a constant value.
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