Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Var 1/3 | Data Types and Variables
Introduction to JavaScript (staging)
course content

Зміст курсу

Introduction to JavaScript (staging)

Introduction to JavaScript (staging)

1. Introduction
2. JavaScript syntax
3. Data Types and Variables

Var 1/3

Var:

In the very first chapter of the section we learn that there are three ways to declare a variable:

  • let
  • const
  • var

The var is used as an alternative to the let keyword. We can replace let with the var or vice-versa but there are some exceptions.

Завдання

Declare a variable with the identifier name customers and assign the value 1000 by using the var keyword. Show the value on the console.

Завдання

Declare a variable with the identifier name customers and assign the value 1000 by using the var keyword. Show the value on the console.

Var has No Block Scope

Variables have either local-scope or global-scope. The code which is enclosed inside the {} is called a block of code. Variables declared with var are accessible outside the block as well, for example.

1234
if (10 > 5){ var test = true; } console.log(test);
copy

But if we declare the test variable with the let keyword we get an error.

1234
if (10 > 5){ let test = true; } console.log(test);
copy

As you can see that the test variable was accessible outside the if statement when declared with the var keyword, but it was not accessible when declared with the let keyword.

Note: Scoping is an advanced topic therefore this part has no exercise because we will learn more about the scope in the upcoming chapters.

Перейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів

Все було зрозуміло?

Секція 3. Розділ 4
toggle bottom row

Var 1/3

Var:

In the very first chapter of the section we learn that there are three ways to declare a variable:

  • let
  • const
  • var

The var is used as an alternative to the let keyword. We can replace let with the var or vice-versa but there are some exceptions.

Завдання

Declare a variable with the identifier name customers and assign the value 1000 by using the var keyword. Show the value on the console.

Завдання

Declare a variable with the identifier name customers and assign the value 1000 by using the var keyword. Show the value on the console.

Var has No Block Scope

Variables have either local-scope or global-scope. The code which is enclosed inside the {} is called a block of code. Variables declared with var are accessible outside the block as well, for example.

1234
if (10 > 5){ var test = true; } console.log(test);
copy

But if we declare the test variable with the let keyword we get an error.

1234
if (10 > 5){ let test = true; } console.log(test);
copy

As you can see that the test variable was accessible outside the if statement when declared with the var keyword, but it was not accessible when declared with the let keyword.

Note: Scoping is an advanced topic therefore this part has no exercise because we will learn more about the scope in the upcoming chapters.

Перейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів

Все було зрозуміло?

Секція 3. Розділ 4
toggle bottom row

Var 1/3

Var:

In the very first chapter of the section we learn that there are three ways to declare a variable:

  • let
  • const
  • var

The var is used as an alternative to the let keyword. We can replace let with the var or vice-versa but there are some exceptions.

Завдання

Declare a variable with the identifier name customers and assign the value 1000 by using the var keyword. Show the value on the console.

Завдання

Declare a variable with the identifier name customers and assign the value 1000 by using the var keyword. Show the value on the console.

Var has No Block Scope

Variables have either local-scope or global-scope. The code which is enclosed inside the {} is called a block of code. Variables declared with var are accessible outside the block as well, for example.

1234
if (10 > 5){ var test = true; } console.log(test);
copy

But if we declare the test variable with the let keyword we get an error.

1234
if (10 > 5){ let test = true; } console.log(test);
copy

As you can see that the test variable was accessible outside the if statement when declared with the var keyword, but it was not accessible when declared with the let keyword.

Note: Scoping is an advanced topic therefore this part has no exercise because we will learn more about the scope in the upcoming chapters.

Перейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів

Все було зрозуміло?

Var:

In the very first chapter of the section we learn that there are three ways to declare a variable:

  • let
  • const
  • var

The var is used as an alternative to the let keyword. We can replace let with the var or vice-versa but there are some exceptions.

Завдання

Declare a variable with the identifier name customers and assign the value 1000 by using the var keyword. Show the value on the console.

Var has No Block Scope

Variables have either local-scope or global-scope. The code which is enclosed inside the {} is called a block of code. Variables declared with var are accessible outside the block as well, for example.

1234
if (10 > 5){ var test = true; } console.log(test);
copy

But if we declare the test variable with the let keyword we get an error.

1234
if (10 > 5){ let test = true; } console.log(test);
copy

As you can see that the test variable was accessible outside the if statement when declared with the var keyword, but it was not accessible when declared with the let keyword.

Note: Scoping is an advanced topic therefore this part has no exercise because we will learn more about the scope in the upcoming chapters.

Перейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Секція 3. Розділ 4
Перейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
We're sorry to hear that something went wrong. What happened?
some-alt