Club75|| Variable and Datatypes of Javascript programming language (part 3) by @christnenye
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.
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".
a 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
without 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
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
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
code of it in visual studio code
Numbers :A number is a datatype that can be an interger, floating value, and an exponential value.
a 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
a code for Boolean
Undefined: An undefined datatype is a variable that is declared but no value assigned to to the variable.
a 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.
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
code 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
Note: You must enter the tag #fintech among the first 4 tags for your post to be reviewed.
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.
Discord Facebook Twitter
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.
Thank you, @christnenye for making this quality post in our community today.
We hope to read more of your quality contents