Posts

Showing posts from April, 2020

08_PASS BY REFERENCE VS PASS BY VALUE ( PRIMITIVE VS NON_PRIMITIVE / REFERENCE VALUE)

Image
JavaScript is dynamically typed language which means types are not defined at compile time like other object-oriented languages. JavaScript provides two categories under which the data types are divided. Primitive Values Reference Values Primitive Values: In JavaScript, a primitive is data that is not an object and has no methods. There are 7 primitive data types: string, number, boolean, null, undefined, symbol, biginit. Most of the time, a primitive value is represented directly at the lowest level of the language implementation. All primitives are immutable, i.e., they cannot be altered. It is important not to confuse a primitive itself with a variable assigned a primitive value. The variable may be reassigned a new value, but the existing value cannot be changed in the ways that objects, arrays, and functions can be altered.” -  Source - MDN To break the above definition, it simply means that in case of primitive values, it creates and assigns a fixed locat...

07_Scoping Concept in JavaScript

Image
          What is Scope? Scoping  itself is how you search for a variable with a given name. A variable has a  scope  which is the whole area in which that variable can be accessed by name. Scope Chain  is used to resolve the value of variable in J.S In Javascript, we can call  Scope  as the set of rules that govern how the  Engine  can look up a variable by its identifier name and find it. There are two types of  Scope  models that are widely used.  By far the most commonly used  Scope  model by vast majority of programming languages is  Lexical Scope,  also JavaScript uses this  Lexical Scope  model .  The other model which is still used by some languages like  Bash  scripting is called  Dynamic Scope . Now, we will discuss what are these  Scope  models? Then we will understand the differences between them. ...

01_Javascript as a Dynamic Typed language

Image
Source Code : Original code (usually typed by a human into a computer) Translation : Converting source code into something a computer can read (i.e. machine code) Run-Time : Period when program is executing commands (after compilation, if compiled) Compiled : Code translated before run-time Interpreted : Code translated on the fly, during execution Typing “When types are checked” :  "3" + 5  will raise a type error in  strongly typed  languages, such as Python and Go, because they don't allow for "type coercion": the ability for a value to change type implicitly in certain contexts (e.g. merging two types using  + ).  Weakly typed  languages, such as JavaScript, won't throw a type error (result:  '35' ). Static : " Types checked before run-time.Static typing can be also considered as limited form of program verification  and in a type-safe language, can be considered also an optimization. If a compiler can prove that a program is well-typed, ...