Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Constant 2/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

bookConstant 2/3

Block Scope of Constants

Declaring a variable with the const keyword is similar to declaring a variable with the let keyword when it comes to Block Scope, for example.

The personName declared in the block, in this example, is not the same as the personName declared outside the block:

12345
const personName = "Mike"; if (2 > 1){ const personName = "Smith"; } console.log(personName)
copy

We gave you a good understanding of block-scope but it is not a good practice to use the same name inside and outside the code block.

Constants are Assigned Values at the time of Declaration

In JavaScript, we can initialize variables in one line and assign them values in the next line with the let and the var keywords but we cannot do that with the const keyword, and if we do so, we get an error, for example.

123456
let age; age = 23; console.log(age) var height; height = 5; console.log(height);
copy

But with const we get an error.

123
const PI; PI = 3.14159265359; console.log(PI);
copy

Завдання

A constant variable named gravity has been given to you. But it cannot be displayed due to some error. Your task is to make changes in the code so that it can be displayed properly.

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

Як ми можемо покращити це?

Дякуємо за ваш відгук!

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

bookConstant 2/3

Block Scope of Constants

Declaring a variable with the const keyword is similar to declaring a variable with the let keyword when it comes to Block Scope, for example.

The personName declared in the block, in this example, is not the same as the personName declared outside the block:

12345
const personName = "Mike"; if (2 > 1){ const personName = "Smith"; } console.log(personName)
copy

We gave you a good understanding of block-scope but it is not a good practice to use the same name inside and outside the code block.

Constants are Assigned Values at the time of Declaration

In JavaScript, we can initialize variables in one line and assign them values in the next line with the let and the var keywords but we cannot do that with the const keyword, and if we do so, we get an error, for example.

123456
let age; age = 23; console.log(age) var height; height = 5; console.log(height);
copy

But with const we get an error.

123
const PI; PI = 3.14159265359; console.log(PI);
copy

Завдання

A constant variable named gravity has been given to you. But it cannot be displayed due to some error. Your task is to make changes in the code so that it can be displayed properly.

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

Як ми можемо покращити це?

Дякуємо за ваш відгук!

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

bookConstant 2/3

Block Scope of Constants

Declaring a variable with the const keyword is similar to declaring a variable with the let keyword when it comes to Block Scope, for example.

The personName declared in the block, in this example, is not the same as the personName declared outside the block:

12345
const personName = "Mike"; if (2 > 1){ const personName = "Smith"; } console.log(personName)
copy

We gave you a good understanding of block-scope but it is not a good practice to use the same name inside and outside the code block.

Constants are Assigned Values at the time of Declaration

In JavaScript, we can initialize variables in one line and assign them values in the next line with the let and the var keywords but we cannot do that with the const keyword, and if we do so, we get an error, for example.

123456
let age; age = 23; console.log(age) var height; height = 5; console.log(height);
copy

But with const we get an error.

123
const PI; PI = 3.14159265359; console.log(PI);
copy

Завдання

A constant variable named gravity has been given to you. But it cannot be displayed due to some error. Your task is to make changes in the code so that it can be displayed properly.

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

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Block Scope of Constants

Declaring a variable with the const keyword is similar to declaring a variable with the let keyword when it comes to Block Scope, for example.

The personName declared in the block, in this example, is not the same as the personName declared outside the block:

12345
const personName = "Mike"; if (2 > 1){ const personName = "Smith"; } console.log(personName)
copy

We gave you a good understanding of block-scope but it is not a good practice to use the same name inside and outside the code block.

Constants are Assigned Values at the time of Declaration

In JavaScript, we can initialize variables in one line and assign them values in the next line with the let and the var keywords but we cannot do that with the const keyword, and if we do so, we get an error, for example.

123456
let age; age = 23; console.log(age) var height; height = 5; console.log(height);
copy

But with const we get an error.

123
const PI; PI = 3.14159265359; console.log(PI);
copy

Завдання

A constant variable named gravity has been given to you. But it cannot be displayed due to some error. Your task is to make changes in the code so that it can be displayed properly.

Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Секція 3. Розділ 10
Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
some-alt