Posts

Showing posts from April, 2022

Shadowing

Image
  What is shadowing in javascript ?   Shadowing: Now, when a variable is declared in a certain scope having the same name defined on its outer scope and when we call the variable from the inner scope, the value assigned to the variable in the inner scope is the value that will be stored in the variable in the memory space. This is known as Shadowing or Variable Shadowing .       What is illegal shadowing ? Illegal Shadowing: Now, while shadowing a variable, it should not cross the boundary of the scope, i.e. we can shadow var variable by let variable but cannot do the opposite. So, if we try to shadow let variable by var variable, it is known as Illegal Shadowing and it will give the error as “variable is already defined.”

How the variable inside the function being Global !

Image
"z will be Global after the first call of the function "  

Variable Scope in javascript

Image
      Scope determines the accessibility (visibility) of variables. JavaScript has 3 types of scope: Block scope Function scope Global scope   1. Block Scope : Before ES6 (2015), JavaScript had only Global Scope and Function Scope . ES6 introduced two important new JavaScript keywords: let and const . These two keywords provide Block Scope in JavaScript.  --------------------------------------------------------------------------------------------- Variables declared inside a { } block cannot be accessed from outside the block: Example: {    let x = 2 ; } // x can NOT be used here    ---------------------------------------------------------------------------------------------- Variables declared with the var keyword can NOT have block scope. Variables declared inside a { } block can be accessed from outside the block.  Example: {    var x = 2 ; } // x CAN be used here       note...

isFinite( )

Image
        isFinite( ); this built in function is used to check if the data Numerical value or String value . isFinite( ) :  Check if a number is finite . isFinite( ) : return true or false depending on the argument.    The isFinite() method returns true if a value is a finite number. Infinite (not finite) values are Infinity , -Infinity , or NaN   for example : isFinite(170538);       \\ return true isFinite("189anbz46");    \\ return false

var VS. let

Image
      Differences Between the var and let Keywords :   Var : One of the biggest problems with declaring variables with the var keyword is that you can easily overwrite variable declarations : var myName = "Hend" ; var myName = "sara" ; console . log (myName ) ; \\ return Sara . In this code ,the myName variable is originally declared as Hend , and is then overridden to be Sara .The console then displays the string Sara . In a small application, you might not run into this type of problem. But as your codebase becomes larger, you might accidentally overwrite a variable that you did not intend to. Because this behavior does not throw an error, searching for and fixing bugs becomes more difficult.  

Declare JavaScript Variables

Image
     In computer science, data is anything that is meaningful to the computer. JavaScript provides eight different data types which are :  undefined null   boolean   string   symbol   bigint   number   object Variables allow computers to store and manipulate data . Variables  are making the code dynamic .

Converting Variables to Numbers

Image
       There are 3 JavaScript methods that can be used to              convert variables to numbers: The Number() method The parseInt() method The parseFloat() method These methods are not number methods, but global JavaScript methods. Global JavaScript Methods JavaScript global methods can be used on all JavaScript data types.   These are the most relevant methods, when working with numbers : Number()   : Returns a number, converted from its argument. parseFloat() : Parses its argument and returns a floating point number. parseInt()   :  Parses its argument and returns an integer .   try it in the console :   Number(10.34) ;       // returns 10.34 parseFloat(2.56);      // returns   2.56   parseInt(2.56);         // returns   2   in all above three methods : If the number cannot...

javascript Basics

Image
 javascript Basics

where can you write javascript code ?

Image
 we can write javascript code :

introduction about javascript

Image
   the Javascript  is the most popular programming Language in the world , especially in building and development the websites .  95%  of the websites are used javascript in it's structure , big companies like Facebook , Google , Amazon , Paypal and  Netflix used javascript to build it's own applications .  As we know we use HTML to build the website structure , CSS for the presentation and javascript to make the website Dynamic because javascript makes the design interactive . where the user can interact with the wbsite . by javascript we can make animation for the images on our web page and also a part of the page can be updated by javascript . all that depends on a certain action the user will take on our web page.