Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Output Using Variables 1/2 | Introduction
Introduction to JavaScript (staging)
course content

Зміст курсу

Introduction to JavaScript (staging)

Introduction to JavaScript (staging)

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

Output Using Variables 1/2

Variable is a piece of memory that has a name and a value.

Here we have a variable age, that stores the numeric value 23.

Printing messages alongwith a variable:

We can also pass some message with values as well, for example.:

You can see from the above example that we displayed a message My age is: 23 with a value of the variable age.

Why should we use the variables?

Variable can store any value, so you can assign it and use it as many times as you need. For example, if you need value 23 ten times, you can create and use a variable age with this value. Then, if you need to change your age, you`ll do it once by changing the variable, not changing all 10 occurrences of your value.

Compare two next examples:

If you need to change your age, in the first example, you'll have to do it three times, and in the second, you'll only change the value of age variable, and then all other occurrences will be changed automatically. That's why we should use the variables.

Note: Always remember to separate the message and the variable with a comma (,) otherwise it will give error and you won't see your desired output.

Завдання

A variable named king has been given to you. Your task is, using this variable, to print the sentence, "The King of the jungle is : Lion". Use the console.log(). It means you should place king variable like on the example.

Завдання

A variable named king has been given to you. Your task is, using this variable, to print the sentence, "The King of the jungle is : Lion". Use the console.log(). It means you should place king variable like on the example.

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

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

Секція 1. Розділ 2
toggle bottom row

Output Using Variables 1/2

Variable is a piece of memory that has a name and a value.

Here we have a variable age, that stores the numeric value 23.

Printing messages alongwith a variable:

We can also pass some message with values as well, for example.:

You can see from the above example that we displayed a message My age is: 23 with a value of the variable age.

Why should we use the variables?

Variable can store any value, so you can assign it and use it as many times as you need. For example, if you need value 23 ten times, you can create and use a variable age with this value. Then, if you need to change your age, you`ll do it once by changing the variable, not changing all 10 occurrences of your value.

Compare two next examples:

If you need to change your age, in the first example, you'll have to do it three times, and in the second, you'll only change the value of age variable, and then all other occurrences will be changed automatically. That's why we should use the variables.

Note: Always remember to separate the message and the variable with a comma (,) otherwise it will give error and you won't see your desired output.

Завдання

A variable named king has been given to you. Your task is, using this variable, to print the sentence, "The King of the jungle is : Lion". Use the console.log(). It means you should place king variable like on the example.

Завдання

A variable named king has been given to you. Your task is, using this variable, to print the sentence, "The King of the jungle is : Lion". Use the console.log(). It means you should place king variable like on the example.

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

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

Секція 1. Розділ 2
toggle bottom row

Output Using Variables 1/2

Variable is a piece of memory that has a name and a value.

Here we have a variable age, that stores the numeric value 23.

Printing messages alongwith a variable:

We can also pass some message with values as well, for example.:

You can see from the above example that we displayed a message My age is: 23 with a value of the variable age.

Why should we use the variables?

Variable can store any value, so you can assign it and use it as many times as you need. For example, if you need value 23 ten times, you can create and use a variable age with this value. Then, if you need to change your age, you`ll do it once by changing the variable, not changing all 10 occurrences of your value.

Compare two next examples:

If you need to change your age, in the first example, you'll have to do it three times, and in the second, you'll only change the value of age variable, and then all other occurrences will be changed automatically. That's why we should use the variables.

Note: Always remember to separate the message and the variable with a comma (,) otherwise it will give error and you won't see your desired output.

Завдання

A variable named king has been given to you. Your task is, using this variable, to print the sentence, "The King of the jungle is : Lion". Use the console.log(). It means you should place king variable like on the example.

Завдання

A variable named king has been given to you. Your task is, using this variable, to print the sentence, "The King of the jungle is : Lion". Use the console.log(). It means you should place king variable like on the example.

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

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

Variable is a piece of memory that has a name and a value.

Here we have a variable age, that stores the numeric value 23.

Printing messages alongwith a variable:

We can also pass some message with values as well, for example.:

You can see from the above example that we displayed a message My age is: 23 with a value of the variable age.

Why should we use the variables?

Variable can store any value, so you can assign it and use it as many times as you need. For example, if you need value 23 ten times, you can create and use a variable age with this value. Then, if you need to change your age, you`ll do it once by changing the variable, not changing all 10 occurrences of your value.

Compare two next examples:

If you need to change your age, in the first example, you'll have to do it three times, and in the second, you'll only change the value of age variable, and then all other occurrences will be changed automatically. That's why we should use the variables.

Note: Always remember to separate the message and the variable with a comma (,) otherwise it will give error and you won't see your desired output.

Завдання

A variable named king has been given to you. Your task is, using this variable, to print the sentence, "The King of the jungle is : Lion". Use the console.log(). It means you should place king variable like on the example.

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