What is JavaScript(JS)?

  • By Pooja Bhavsar
  • March 1, 2024
  • JavaScript
What is JavaScript(JS)?

What is JavaScript(JS)?

JS means JAVASCRIPT. JS is a programming language that is used for converting static web pages to interactive and dynamic web pages. Browser understands JS code by the help of JS engine => V8 in Chrome, Spider Monkey in Firefox, JavaScript in Safari, and chakra in Edge. A JS engine is a program present inside a web browser that executes JS code. In this blog, we will explore What is JavaScript(JS)?, and its features.

JavaScript is a lightweight, cross-platform, single-threaded, and interpreted compiled programming language. It is also known as the scripting language for web pages.

Lightweight => JavaScript is a lightweight programming language, which means that it can run on almost any device without requiring a lot of memory or processing power.

For Free Demo classes Call: 8237077325

Registration Link: Click Here!

 

Single-threaded => Javascript is a single-threaded language, meaning that just one line of code may be run at once. Javascript is single-threaded because, originally, it was only a web browser scripting language created to serve the needs of a single user on a single window of the browser, eliminating the need for multithreading.

Interpreted compiled programming language => JavaScript is an interpreted language, not a compiled language. A program such as C++ or Java needs to be compiled before it is run. The source code is passed through a program called a compiler, which translates it into bytecode that the machine understands and can execute.

 History of JavaScript?

JavaScript is a modern scripting language that is popular worldwide among developers. It was invented in the year 1995 by Brendan Eich. This language became an ECMA standard in the year 1997. The latest version of JS is ES14 ECMAScript launch in 2023 

 Some key points about of JS?

JS is an interpreted language.

JS runtime reads the actual code, not bytecode.

JS allowed to change the variable type during runtime because of this reason JS is a dynamically type language.

In JS for displaying the data we can use => console.log() which prints data on the console and document. write() which prints data on the browser.

For taking input from user we can use => prompt() function => prompt() function only run on Borwser or replit, it will not run inside Visual Studio.

JS is dynamically => it means => let a = 10; here type of => a => is number. let a =’string’; here type of => a => is string this means dynamically type. During run time we can change the variable type because first => a => is number and now it become => string. In JS variable type depends upon the value. Explore Top JavaScript Interview Questions and Answers.

function add(a,b)

{

return a+b;

}

console.log(add(10,20));   => now see o/p it is 30.

 

JS is weakly type =>

let a = 10;

let b = ‘hello’;

let c =a + b;

console.log(c); 

=> o/p => 10hello => here => a => also become string this is called weakly type. Weakly typing means in JS we can add strings with numbers but in another programming language it is not possible. And in JS we don’t have to specify the datatype of a variable which also makes JS as a weakly type programming language.

Pros of JS?

  • popular language.
  • easy to learn.
  • used widely with frontend and backend technologies.

 Cons of JS?

It is browser support and we have so many browsers nowadays. So sometimes JS works on Chrome and not work on Firefox and vice versa. To solve this we have to write JS according to the browser and this is a problem for different browsers we have to write the same code in different ways.

Security concern => means by => inspect => source => any site we can see all the JS code of that site easily.

JS is evolving very quickly.

JavaScript Variables?

In applications, sometimes we need to use data, so for storing that data we use some containers in a programming language which we call variables. Variable value we can change in the future. Constant value cannot be changed in the future.

var a = ‘4’;  

 var is => variable =>  and name of the varibale is => a => value of variable is => 4.

es5 old java script => var

es6 new java script => let and const

There are two types of variables in JavaScript which are listed below:

Local variables: Declare a variable inside of a block or function.

Global variables: Declare a variable outside function or with a window object.

Previously JS does not know about scope {}.

 

For Free Demo classes Call: 8237077325

Registration Link: React JS Training in Pune!

 

Difference between var and let?

1) var comes from old JS(es5) and let comes from new JS(es6). In es6 const will also introduce.

2) var is function scoped and let is braces scoped

function abc()

{

for(var i=1; i<12; i++)

{

    console.log(i);

}

}

abc();               => here function is called

=> see o/p  1 2 3 4 5 6 7 8 9 10 11

by this we can say that we can use this var in anywhere in this abcd() function or in anywhere in the nearest function. To run any function we have to call that function.

To run the code => node “d:\Front\code\script.js”

 

 

 

function abc()

{

for(var i=1; i<12; i++)

{

    console.log(i);

}

console.log(i);

}

abc();            => see o/p   1 2 3 4 5 6 7 8 9 10 11 12

 

like if we come out form the => for loop => still we can use this var but in other programming language we can not do this.

let => is not function scoped => let => is braces{} scoped. It means

function abc()

{

for(let i=1; i<12; i++){

      console.log(i);

}

}

abc();        => see o/p 1 2 3 4 5 6 7 8 9 10 11

 

now we can only use or access this let variable => i => only inside its braces or only inside => for loop => like

function abc()

{

for(let i=1; i<12, i++){

     console.log(i);

}

console.log(i);

}

abc();        => see o/p 1 2 3 4 5 6 7 8 9 10 11  Error => i => is not define => because we cannot use let variable outside the braces

—————————–

var a = “hello”;

{

let a = “hii”;

     console.log(a);            

}

console.log(a);          o/p => hii hello => here this => hii => is because of let and => hello => is because of => var

—————————–

var can be update and re-declared within its scope =>

var a = “hello”;

var a = “bye”;

{

let a = “hii”;

     console.log(a);            

}

console.log(a)            => o/p => hii bye      

———————————-

let can be update but not re-declared within its scope =>

var a = “hello”;                 => this is allowed

var a = “bye”;                   => this is allowed

{

let a = “hii”;         

let a = “you”;             => this is not allowed and gives error => identifier => a => has already been declared

     console.log(a);            

}

console.log(a); 

————————————

let a = “hello”;

{ let a = “hii”;

     console.log(a);            

}

console.log(a);           => o/p => hii   hello

—————————————–

var a = “hello”;

{

  var a = “hii”;

     console.log(a);            

}

console.log(a);       => o/p => hii hii

————————-

 

 

 

 

 

 

let a = “hello”;

a= 7;

{

let a = “hii”;

     console.log(a);            

}

console.log(a);      => o/p => hii   7

—————————

var and let  variable are initialized with undefine whereas const variables are not initialized undefined

var a;  let b;   => this is allowed

 

const c; => this is not allowed it will show error

 

const c = 20;          => this is allowed

 

3) var join its self in window object but let and const not do this.

 Must watch our video on Demand For Full Stack Developers in Future

 

Author:-

Pooja Bhavsar
Call the Trainer and Book your free demo class for JAVASCRIPT now!!!

© Copyright 2020 | SevenMentor Pvt Ltd.

Submit Comment

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

*
*