let in javascript : variables

Posted under javascript sample code On By mohammed.mutawe

Let in JavaScript

Let in JavaScript are an important part and in order to understand how they work, you must realize a little knowledge in the computer’s memory because this will greatly help in moving to other, more complex topics in the language.

In this lesson, you will understand what variables are and how they work in JavaScript scripts by assigning values ​​to them and then starting to show results on the computer screen.



  • Understanding variable in JavaScript.
  • Benefits of Variables.
  • Declaring variables.
  • Variable Types.



Variables in JavaScript are no different from others in other programming languages, and if you want to define a variable, the easiest way to do so is as follows:

/*Declaring variable*/
let x = 2;


Understanding variables

You can use let in JavaScript, and this is a common method in expert libraries and variables usually provide a value that can be changed at any time that is called for, and to understand this well, there is a short way to define a variable:

/*Declare variable in short*/
x = 2;

This is a correct method and acceptable to the translator, and if you defined it previously and in one way or another it must be changed, you will give it a value in this way, for example:

/*Declare variable in short*/
x = 10;

The variable name remains the same, and this is a prerequisite when giving a value to the variable more than once in the code, especially if it is very large.


Benefits of Variables

There are many benefits to variables in JavaScript:

  • It indicates how the code works, just like math algorithms, and let in JavaScript are the best way to define variables.
  • Shortening a lot of time and extending the code to help solve the knot.
  • Code clarity.


Declaring Variables

When defining the variable, you will need three basic factors, the first is the definition by means of a reserved word in the programming language such as Let in javascript or var, the second factor is to add text to this variable so that you can call it every time you will use it,
and the third factor is to equate this text with a numeric, text, or decimal value or whatever Like.


Assigning between variables

When you define a variable in JavaScript and give it a value, or maybe you want a constant variable that is not affected by the programming operations,
you can define another variable and equal it to the constant variable as a kind of stripping the values ​​from the direct effect:

/*Assigning between variables*/
var val_1 = 10;
var val_2 = val_1;


Naming variables

There are limited ways of naming variables in order to be accepted in the compiler, as there are some ways that cannot be accepted. That’s why we’ll show you the right and wrong ways to try to avoid:


  • tajersys
  • _tajersys
  • tajer2sys
  • tajer_sys
  • tajer_sys_654

Not allowed

  • #tajersys
  • 1tajersys
  • tajer sys
  • tajer_sys 2
  • _tajer sys

Variable types

In the previous examples, we focused on numbers in defining variables because they are the best for understanding above all,
but what if we want variables with names or logical values, JavaScript has included this as well in defining variables and their types.

You are likely to include text inside the variable and this is really possible or for example to include a value of NULL and this is provided by JavaScript and all programming languages​also in ways specific to each language.


You can define numbers and we will use Let in JavaScript as follows:

let a = 1;
let b = 20.50;
var c = 0;
var d = 20;



In JavaScript language, you can define a variable of type string and put a text, word, or even a letter in it, so that it becomes as follows:

var myJob = "Programmer";
var name = "Violet jack";
var H_W = "Hello World! , JavaScript";



It may be useful to use Boolean operators a lot in JavaScript, and you may need it in your large code to look like this:

var tap_on = true;

if(tap_on )
   tap_on = false;



Copy this code inside your editor then try to see results on your browser :

<script type="text/javascript">
    var is_true=true;
    var is_nada=null;
    var estimatedCoast=15.59;
    var johnText = "john said this project is amazing!";



  • Third edition JavaScript

Leave a comment

Your email address will not be published. Required fields are marked *