Club75|| Variable and Datatypes of Javascript programming language (part 3) by @christnenye

in CampusConnect2 years ago (edited)

Hello everyone, trust you'll are doing great?

Every programming language has variable and Datatypes acceptable to it and JavaScript is not exempted. So today I will be writing on variables and Datatypes of Javascript programming language.

20220814_161636.jpg

VARIABLE IN JAVASCRIPT PROGRAMMING LANGUAGE

A Variable is a memory location that may assume any given value or set of values. In Javascript programming language there is three ways of setting Variables which includes var, let and const.

Var: var has been used since the beginning of Javascript, however one don't really have to use it anymore because of the new update with huge functionality in using let and const reason is that var is globally scope( this is where a variable is accessible from anywhere, both inside and outside a block) there would be a conflict and this can cause problem which is considered a poor practice thus that is why var is not necessary needed anymore.

Illustration of using "var"
Note: in the code below, "a" is declared with var and it can only be used inside the function "greet".

chy 7.PNGa code showing a var

Let: Setting Variable using Let was added with ECMAScript specification( a specification for creating scripting language and JavaScript is an implementation of that blueprint) of 2015, and that was a new update with a huge functionality of re-assigning values and not initializing values to variables.

Illustration of using let without initializing a value to a Variable
(Using visual studio code)

Let score;------- un-initialized
Score=30;
Console.log(score)
Output:30
edh.PNGwithout initializing values

An illustration using let to set a value to a Variable and re-assigning a value to the same variable

Let score=30;
Score=31;----re-assigned variable
Console.log(score)
Output:31
Below is the code on visual studio code
ssdn.PNG

Const:Const is a short form for Constant. Setting Variable using const was also added to ECMAScript specification of 2015. Using const all values set to it remain unchanged and cannot be directly re-assigned but using const makes codes to be more robust, more secure and less prone to error.

Illustration of using const to set a Variable is below

Const age=30;
Console.log(age)
Output:30
gjk,hi.PNG

The new ways of setting Variable using let and const is understandable in knowing that using let one can re-assign values to already assigned Variable name and in using const once a value is assigned it can't be changed, also in using const you must initialize a value to a Variable.

DATATYPES IN JAVASCRIPT PROGRAMMING LANGUAGE

Datatypes: A Datatypes is a set of possible values acceptable and possible operation allowed to be used on the values. There are two different types of Datatypes which include primitive datatype a type of datatype in which data is directly assigned to memory and non-primitive datatype a type of datatype in which data is not directly assigned to a memory.

In Javascript programming language the primitive datatype accepts single value which are String, Numbers, Boolean, Null and Undefined.

String: A string typically is a sequence of characters either a constant or Variable. In Javascript alot of can be done to string which include

Using the declaration below
Const name='christnenye';
Const age=15;

  • Concatenation a string
  • Length of string
  • Popping a string
  • Changing the case of a string
  • Splitting a string and many of them

chy.PNGcode of it in visual studio code

Numbers :A number is a datatype that can be an interger, floating value, and an exponential value.

chy 2.PNGa code interger, floating and exponential value in visual studio code

Boolean:A Boolean is a datatype that comprises of only two values, true and false. It's used in conditional statement

chy 1.PNG
a code for Boolean

Undefined: An undefined datatype is a variable that is declared but no value assigned to to the variable.

chy 4.PNGa code showing Undefined datatype

Null: A null datatype is a datatype denoted with only one value in Javascript null. Also, a null is variable declared with no value.

CHY 5.PNG

Testing the Datatypes

Const name="Christnenye"; //string datatype
const age=30; //Number datatype
const is cool=true; // Boolean datatype
Const X= null; //NULL datatype
const y; //Undefined datatype

chy 6.PNGcode for running type of datatypes

Note: all the above codes is correct and when run gives the required output for the stated function.


CONCLUSION
Javascript makes use of var,let and const to set Variable and Variable is a name of a memory location. Var has always being used to set Variable until an update in ECMAScript specification 2015 brought about let and const which is widely used now but that doesn't mean that var is no longer used. Javascript also, makes use of string, number, Boolean, null, Undefined and symbol Datatypes which are primitive datatype and object which are none primitive datatype.

This is all about variable and Datatypes, in the next publication I will be writing on arrays.

Thanks for reading

Sort:  
Your post has been successfully curated by our team via @ozenozge at 30%. Thank you for your committed efforts, we invite you to do more and keep posting high quality posts for a chance to win valuable upvotes from our team of curators and probable selection for an additional upvote later this week in the Top Seven.

received_388032689541375-1.jpeg

Note: You must enter the tag #fintech among the first 4 tags for your post to be reviewed.

 2 years ago 

Thanks ma @ozenozge, for appreciating me.

Congratulations, your post has been supported by @steem4nigeria. This is the official community account of Nigerians on Steemit. You can reach us here on our community account.

Manual Curator : @Reminiscence01

Subscribe and Join Steem4Nigeria Telegram
Discord Facebook Twitter

 2 years ago 

Hello @christnenye, thanks for publishing this post in Campus Connect community,

Your post has been supported using Campus Connect Curation account.

Keep publishing original and quality posts in Campus Connect community.

C3TZR1g81UNaPs7vzNXHueW5ZM76DSHWEY7onmfLxcK2iPTpz7Uq5ujHgG4nBFxBmGTKURwn9hGbB3jzG2jac9Sd5A7HYfy1ne3WpQ2kRVkj3jqhCeMGVux (1).png

Curated by : @jueco

 2 years ago 

Thank you, @christnenye for making this quality post in our community today.
We hope to read more of your quality contents

Criteria RemarkGrade
Quality2.5 /3
Markdown/presentation2.0/2.5
#clubclub50/75/1001 /1
Verified user1/1
Plagiarism free1/1
#steemexclusive1 /1
Bot free0.5/0.5
Total-9.0/10

Coin Marketplace

STEEM 0.21
TRX 0.20
JST 0.034
BTC 98477.90
ETH 3327.94
USDT 1.00
SBD 3.07