Skip to main content

Variables

@serverSerrverlesskiy

Variables#

Variables ๐Ÿ”” (Variables, abbreviated as var) are a container, for values such as numbers used in addition โž•, or a string that we could use as part of a sentence, and other data types that we'll get to know later.

Container

Variable declaration#

Announcement

To use a variable, you must first create it, or, more precisely, declare a variable. To do this, we introduce the keyword var followed by the name you want to give your variable. The instruction below creates (in other words: declares or defines) a variable named "message":

Live Editor
Result
SyntaxError: Unexpected token (1:8)
1 : return ()
            ^

Here we create a variable ๐Ÿ”” message. Currently โฑ๏ธ it does not contain a value, to be more precise, the variable contains an empty string.

Assigning a value to a variable#

Memory

Once the variable ๐Ÿ”” is declared, it can be assigned a value. To do this, write ๐Ÿ–Š๏ธ variable name ๐Ÿ””, followed by an equal sign =, followed by the value you want to assign. For example ๐Ÿ‘‡:

Live Editor
Result
SyntaxError: Unexpected token (1:8)
1 : return ()
            ^

In RESULT, the value that you assigned to the variable ๐Ÿ”” returned in the console. Play around ๐ŸŽฎ with the values of a variable ๐Ÿ””, for example, complete the expression with your name.

For brevity, you can combine the declaration of a variable ๐Ÿ”” and writing ๐Ÿ–Š๏ธ in one line ๐Ÿ‘‡:

Live Editor
Result
SyntaxError: Unexpected token (1:8)
1 : return ()
            ^

Payment#

Now you are on a stripped-down version of the site, after subscribing to Patreon, you will get full access to the training course, as well as access to our server's private channels in Discord.

Download our mobile application or get tested in our JavaScript telegram bot, and also subscribe to our news.

Become a Patron!

Sumerian school

Sarasvati8087#Sarasvati8087

Contributors โœจ#

Thanks goes to these wonderful people (emoji key):


Dmitriy Vasilev

๐Ÿ“–

Resoner2005

๐Ÿ› ๐ŸŽจ ๐Ÿ–‹

Become a Patron!