create account

Learning JavaScript--(Starting New Course) ---Learning JS Variables . by pakgamer

View this thread on: hive.blogpeakd.comecency.com
· @pakgamer ·
$6.30
Learning JavaScript--(Starting New Course) ---Learning JS Variables .
## Hello People!
In the previous post, we have started many programming tutorials, We have learned some basics of C++ and node.js with the help of some projects like discord bot, Hive Account details showing bot and much more. But before we jump in all those we need to start learning from very basics and we need to move slowly and step by step. So that's why I felt that I should start JavaScript from the very beginning and learn step by step. From now on we will learn a single topic in a single post because of programming needs practices when you learn a thing here you will need to practice it in order to remember it for the long term. So let's start our first JavaScript tutorial.

## What is JavaScript.

``To learn coding JS we need to understand JavaScript first so JavaScript (JS) is a lightweight, interpreted, or just-in-time compiled programming language with first-class functions. While it is most well-known as the scripting language for Web pages, many non-browser environments also use it, such as Node.js, Apache CouchDB and Adobe Acrobat. JavaScript is a prototype-based, multi-paradigm, single-threaded, dynamic language, supporting object-oriented, imperative, and declarative (e.g. functional programming) styles. Javascript is used by well-known companies like Google, Youtube Gmail, Wikipedia and many more.``


# Today's Topic.
In the post, we will cover JavsScript Variables.


## JavaScript Variables.

Variables in a programming language are used to store value. We use variables to values like string data, numeric, Floating, etc. The data stored in the variable can be called just by calling the variable. For Example, We want to display a message "Hello World" on console 5 times then instead of writing the whole string "Hello World" We can assign this string to a variable and then we will just need to call that variable. We can use a loop for displaying repetition but the loop is not our topic for now. Let's understand the variables with the help of coding.

* Let's open Visual studio code.

![image.png](https://images.hive.blog/DQmPQRH13VXdKadrAsCKkdBNmLa2vwLAwHFRHZxo3M8Xnap/image.png)

* To run our script we will need to HTML. so let's write a basic HTML syntax. If you are using VS code just like me then write ``!`` and click enter.

![image.png](https://images.hive.blog/DQmRW78txbHmvMUognbMN5B6F8zAGuf2UqBB2ezLgP61ypg/image.png)


* Now click Enter.

![image.png](https://images.hive.blog/DQmR7aLuRjEtjkeNAFBWjjwPrVbza821oeieYLVK2VrGUPB/image.png)

* Let's create a variable and assign some string value to it. But we will do it inside the script tag.


![image.png](https://images.hive.blog/DQmXhJwb8NGKcA5PdDrpscmeQGSj5eCXJetMEaEzR34UQjr/image.png)

* We will create a variable with name text and assign "This is hive tutorial by pakgamer" to it.


![image.png](https://images.hive.blog/DQmdFMbgZRaN6PTsAHSQfwrga5pQKJs1kRYRLn34wsnjzJD/image.png)


* Now let's call the variable in the alert.


![image.png](https://images.hive.blog/DQma8fmt6B41oo2kA3uBqsSS35jEfTeXiKg3rh3xzz6cqjh/image.png)

* Let's run the script by clicking mouse right-click and then click on run with live server.

![image.png](https://images.hive.blog/DQmfTJ5xemoZRauUpUjo6jwJTy7z1i74WjYzFs8EL6wnDRQ/image.png)



![image.png](https://images.hive.blog/DQmREGKijStjNiZ46dH4kKXyz9ibqwJXVW9vJGMyWcMXwq7/image.png)

* And you can see the message assigned to the variable in the alert box.


* One more thing I want to tell you that the value of a variable can be changed. A VAR or LET variables are not content it means that its value can be changed. Let's change its value for the sake of example.


![image.png](https://images.hive.blog/DQmNV5PjYGM6iuRL9CdboRkNVF9QyfVmBu2nTori2dTi7ZS/image.png)


* As we can see in the above pic the value the variable is changed. Now let's change the variable type to const and then see what happens.

![image.png](https://images.hive.blog/DQmNtjC2iwuVvsTXf3LbakedToDPwuJgYjmy12F5iCXH6wA/image.png)
* Nothing is displaying on the screen.

![image.png](https://images.hive.blog/DQmcAZjwMWWu3WbCEgVfRdrYJn6P7JCTxjt71ExjpEoZarb/image.png)

* let's inspect why the page is blank.

![image.png](https://images.hive.blog/DQmNscH5GNpQ6Lj2ZpTsienSpa42naMFJwgc6niEH2gJFt2/image.png)


![image.png](https://images.hive.blog/DQmWDnfFtQzgK5AncCejpkJhh4vR9QT9hMJp7WwuYcGuvvQ/image.png)

* As we can see that the console is telling us that we are changing the value of a constant variable which is not possible.

* Next thing is a local variable and global variables. So just like its names local variable can be accessed within the function in which it is defined and global variables can be accessed globally.

### Script.
```
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    


    <script>
    
    const text="This is hive tutorial by pakgamer"; // Constant variable. so its value cannot be changed 
        var text1=" Hive post ";
    text="this is new message"; //CHECKING IF ITS VALUES CHANGED
        text1="new text"; // Assigning new value to the pervios define variable
    alert(text);
    
    
     </script>
</body>
</html>

```


That's all for today. Take care.
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,
properties (23)
authorpakgamer
permlinklearning-javascript-starting-new-course-learning-js-variables
categoryhive-148441
json_metadata{"tags":["programming","gems","coding","hivedevs"],"image":["https://images.hive.blog/DQmPQRH13VXdKadrAsCKkdBNmLa2vwLAwHFRHZxo3M8Xnap/image.png","https://images.hive.blog/DQmRW78txbHmvMUognbMN5B6F8zAGuf2UqBB2ezLgP61ypg/image.png","https://images.hive.blog/DQmR7aLuRjEtjkeNAFBWjjwPrVbza821oeieYLVK2VrGUPB/image.png","https://images.hive.blog/DQmXhJwb8NGKcA5PdDrpscmeQGSj5eCXJetMEaEzR34UQjr/image.png","https://images.hive.blog/DQmdFMbgZRaN6PTsAHSQfwrga5pQKJs1kRYRLn34wsnjzJD/image.png","https://images.hive.blog/DQma8fmt6B41oo2kA3uBqsSS35jEfTeXiKg3rh3xzz6cqjh/image.png","https://images.hive.blog/DQmfTJ5xemoZRauUpUjo6jwJTy7z1i74WjYzFs8EL6wnDRQ/image.png","https://images.hive.blog/DQmREGKijStjNiZ46dH4kKXyz9ibqwJXVW9vJGMyWcMXwq7/image.png","https://images.hive.blog/DQmNV5PjYGM6iuRL9CdboRkNVF9QyfVmBu2nTori2dTi7ZS/image.png","https://images.hive.blog/DQmNtjC2iwuVvsTXf3LbakedToDPwuJgYjmy12F5iCXH6wA/image.png","https://images.hive.blog/DQmcAZjwMWWu3WbCEgVfRdrYJn6P7JCTxjt71ExjpEoZarb/image.png","https://images.hive.blog/DQmNscH5GNpQ6Lj2ZpTsienSpa42naMFJwgc6niEH2gJFt2/image.png","https://images.hive.blog/DQmWDnfFtQzgK5AncCejpkJhh4vR9QT9hMJp7WwuYcGuvvQ/image.png"],"app":"hiveblog/0.1","format":"markdown"}
created2020-04-04 11:01:33
last_update2020-04-04 11:01:33
depth0
children1
last_payout2020-04-11 11:01:33
cashout_time1969-12-31 23:59:59
total_payout_value3.168 HBD
curator_payout_value3.136 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length5,265
author_reputation19,304,605,112,640
root_title"Learning JavaScript--(Starting New Course) ---Learning JS Variables ."
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id96,703,947
net_rshares18,497,742,713,228
author_curate_reward""
vote details (65)
@maxwellmarcusart ·
The hardest thing I will every thought of learn is coding even though I enjoy analysing figures. I wish you the best in your new course.
👍  
properties (23)
authormaxwellmarcusart
permlinkq89gz8
categoryhive-148441
json_metadata{"app":"hiveblog/0.1"}
created2020-04-04 11:24:00
last_update2020-04-04 11:24:00
depth1
children0
last_payout2020-04-11 11:24:00
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length136
author_reputation1,211,731,459,381,109
root_title"Learning JavaScript--(Starting New Course) ---Learning JS Variables ."
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id96,704,255
net_rshares2,386,510,966
author_curate_reward""
vote details (1)