SlideShare a Scribd company logo
1 of 40
JavaScript
Megha V
Asst. Professor
Dept. of IT
Kannur University
14-10-2022 1
meghav@kannuruniv.ac.in
Introduction to JavaScript
• JavaScript is a lightweight, cross-platform, and interpreted compiled
programming language which is also known as the scripting language for
webpages.
• It is well-known for the development of web pages, many non-browser
environments also use it.
• A scripting language is a programming language that employs a high-level
construct to interpret and execute one command at a time.
• In general, scripting languages are easier to learn and faster to code in than
more structured and compiled languages such as C and C++.
14-10-2022 2
meghav@kannuruniv.ac.in
Introduction to JavaScript
• JavaScript can be used for Client-side developments as well
as Server-side developments.
Client-side Programming :
• It is the program that runs on the client machine (browser) and
deals with the user interface/display and any other processing
that can happen on client machine like reading/writing cookies.
1) Interact with temporary storage
2) Make interactive web pages
3) Interact with local storage
4) Sending request for data to server
5) Send request to server
6) work as an interface between server and user
14-10-2022 3
meghav@kannuruniv.ac.in
• The Programming languages for client-side programming are :
1) JavaScript
2) VBScript
3) HTML
4) CSS
5) AJAX
14-10-2022 4
meghav@kannuruniv.ac.in
Server-side Programming :
• It is the program that runs on server dealing with the generation
of content of web page.
1) Querying the database
2) Operations over databases
3) Access/Write a file on server.
4) Interact with other servers.
5) Structure web applications.
6) Process user input.
• For example if user input is a text in search box, run a search
algorithm on data stored on server and send the results.
14-10-2022 5
meghav@kannuruniv.ac.in
• Examples :
The Programming languages for server-side programming are :
1) PHP
2) C++
3) Java and JSP
4) Python
5) Ruby on Rails
14-10-2022 6
meghav@kannuruniv.ac.in
• Javascript is both imperative and declarative type of language.
• JavaScript contains a standard library of objects,
like Array, Date, and Math, and a core set of language
elements like operators, control structures, and statements.
14-10-2022 7
meghav@kannuruniv.ac.in
Client-side:
• It supplies objects to control a browser and its Document Object Model
(DOM).
• When a web page is loaded, the browser creates
a Document Object Model of the page.
The HTML DOM is a standard object model and programming interface for
HTML. It defines:
• The HTML elements as objects
• The properties of all HTML elements
• The methods to access all HTML elements
• The events for all HTML elements
14-10-2022 8
meghav@kannuruniv.ac.in
• Like if client-side extensions allow an application to place elements on
an HTML form and respond to user events such as mouse clicks, form
input, and page navigation.
• Useful libraries for the client-side are AngularJS, ReactJS, VueJS and
so many others.
14-10-2022 meghav@kannuruniv.ac.in 9
Server-side:
• It supplies objects relevant to running JavaScript on a server.
• Like if the server-side extensions allow an application to
communicate with a database, and provide continuity of
information from one invocation to another of the application, or
perform file manipulations on a server.
• The useful framework which is the most famous these days
is node.js.
14-10-2022 10
meghav@kannuruniv.ac.in
Imperative language
• In this type of language we are mostly concern about how it is
to be done.
• It simply control the flow of computation .
• The procedural programming approach , object, oriented
approach comes under this.
14-10-2022 11
meghav@kannuruniv.ac.in
Declarative programming –
• In this type of language we are concern about how it is to be
done , basically here logical computation require .
• Here main goal is to describe the desired result without direct
dictation on how to get it like arrow function do.
14-10-2022 12
meghav@kannuruniv.ac.in
JavaScript can be added to your HTML file
in two ways:
• Internal JS: We can add JavaScript directly to our HTML file by
writing the code inside the <script> tag.
• The <script> tag can either be placed inside the <head> or the
<body> tag according to the requirement.
• External JS: We can write JavaScript code in other file having
an extension .js and then link this file inside the <head> tag of
the HTML file in which we want to add this code.
14-10-2022 13
meghav@kannuruniv.ac.in
Syntax:
<script>
// JavaScript Code
</script>
14-10-2022 14
meghav@kannuruniv.ac.in
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<title>
Basic Example to Describe JavaScript
</title>
</head>
<body>
<!-- JavaScript code can be embedded inside
head section or body section -->
<script>
console.log("Welcome to GeeksforGeeks");
</script>
</body>
</html>
14-10-2022 15
meghav@kannuruniv.ac.in
External JS
function myFunction() {
document.getElementById("demo").innerHTML = "Paragraph changed.";
}
• External scripts are practical when the same code is used in many
different web pages.
• JavaScript files have the file extension .js.
• To use an external script, put the name of the script file in the src
(source) attribute of a <script> tag:
<script src="myScript.js"></script>
14-10-2022 meghav@kannuruniv.ac.in 16
History of JavaScript:
• It was created in 1995 by Brendan Eich while he was an
engineer at Netscape.
• It was originally going to be named LiveScript but was
renamed.
• Unlike most programming languages, the JavaScript language
has no concept of input or output.
• It is designed to run as a scripting language in a host
environment, and it is up to the host environment to provide
mechanisms for communicating with the outside world.
• The most common host environment is the browser.
14-10-2022 17
meghav@kannuruniv.ac.in
Features of JavaScript:
• According to a recent survey conducted by Stack Overflow,
JavaScript is the most popular language on earth.
• With advances in browser technology and JavaScript having
moved into the server with Node.js and other frameworks,
JavaScript is capable of so much more.
• Here are a few things that we can do with JavaScript:
14-10-2022 18
meghav@kannuruniv.ac.in
• JavaScript was created in the first place for DOM manipulation.
• Earlier websites were mostly static, after JS was created
dynamic Web sites were made.
• Functions in JS are objects.
• They may have properties and methods just like another object.
• They can be passed as arguments in other functions.
• Can handle date and time.
• Performs Form Validation although the forms are created using
HTML.
• No compiler is needed.
14-10-2022 19
meghav@kannuruniv.ac.in
Variables and Datatypes in JavaScript
Datatypes in JavaScript
• There are majorly two types of languages.
• First, one is Statically typed language where each variable
and expression type is already known at compile time.
• Once a variable is declared to be of a certain data type, it
cannot hold values of other data types.
• Example: C, C++, Java.
14-10-2022 20
meghav@kannuruniv.ac.in
// Java(Statically typed)
int x = 5 // variable x is of type int and it will not
store any other type.
string y = 'abc' // type string and will only accept
string values
Other, Dynamically typed languages: These languages can
receive different data types over time. For example- Ruby, Python,
JavaScript, etc.
// Javascript(Dynamically typed)
var x = 5; // can store an integer
var name = 'string'; // can also store a string.
14-10-2022 21
meghav@kannuruniv.ac.in
• JavaScript is a dynamically typed (also called loosely typed)
scripting language.
• That is, in JavaScript variables can receive different data types
over time.
• Datatypes are basically typed data that can be used and
manipulated in a program.
14-10-2022 22
meghav@kannuruniv.ac.in
• The latest ECMAScript(ES6)-European Computer Manufacturers Association
Script standard defines following data types:
• Out of which six data types are Primitive(predefined).
•Numbers: Represent both integer and floating-point numbers. Example: 5,
6.5, 7 etc.
•String: A string is a sequence of characters. In JavaScript, strings can be
enclosed within the single or double quotes. Example: “Hello GeeksforGeeks”
etc.
•Boolean: Represent a logical entity and can have two values: true or false.
•Null: This type has only one value : null.
•Undefined: A variable that has not been assigned a value is undefined.
14-10-2022 23
meghav@kannuruniv.ac.in
• Symbol: Unlike other primitive data types, it does not have any
literal form.
• It is a built-in object whose constructor returns a symbol-that is
unique.
• bigint: The bigint type represents the whole numbers that are
larger than 253-1.
• To form a bigint literal number, you append the letter n at the
end of the number.
• Object: It is the most important data-type and forms the building
blocks for modern JavaScript.
14-10-2022 24
meghav@kannuruniv.ac.in
Variables in JavaScript:
• Variables in JavaScript are containers that hold reusable data. It
is the basic unit of storage in a program.
• The value stored in a variable can be changed during program
execution.
• A variable is only a name given to a memory location, all the
operations done on the variable effects that memory location.
• In JavaScript, all the variables must be declared before they
can be used.
14-10-2022 25
meghav@kannuruniv.ac.in
• Before ES2015, JavaScript variables were solely declared using the var
keyword followed by the name of the variable and semi-colon.
• Below is the syntax to create variables in JavaScript:
var var_name;
var x;
• The var_name is the name of the variable which should be defined by
the user and should be unique.
• These types of names are also known as identifiers.
14-10-2022 26
meghav@kannuruniv.ac.in
• The rules for creating an identifier in JavaScript are, the name of
the identifier should not be any pre-defined word(known as
keywords), the first character must be a letter, an underscore (_),
or a dollar sign ($).
• Subsequent characters may be any letter or digit or an
underscore or dollar sign.
• Notice in the above code sample, we didn’t assign any
values to the variables. We are only saying they exist. If you
were to look at the value of each variable in the above code
sample, it would be undefined.
• We can initialize the variables either at the time of
declaration or also later when we want to use them.
14-10-2022 27
meghav@kannuruniv.ac.in
Below are some examples of declaring and
initializing variables in JavaScript:
// declaring single variable
var name;
// declaring multiple variables
var name, title, num;
// initializing variables
var name = "Harsh";
name = “Anu";
14-10-2022 28
meghav@kannuruniv.ac.in
JavaScript is also known as untyped language.
This means, that once a variable is created in JavaScript
using the keyword var, we can store any type of value in this
variable supported by JavaScript. Below is the example for
this:
// creating variable to store a number
var num = 5;
// store string in the variable num
num = "GeeksforGeeks";
14-10-2022 29
meghav@kannuruniv.ac.in
• The above example executes well without any error in JavaScr
unlike other programming languages.
• Variables in JavaScript can also evaluate simple mathematical
expressions and assume their value.
// storing a mathematical expression
var x = 5 + 10 + 1;
console.log(x); // 16
14-10-2022 30
meghav@kannuruniv.ac.in
• After ES2015, we now have two new variable containers: let and const.
• The variable type Let shares lots of similarities with var but unlike var, it
has scope constraints.
• To know more about them visit let vs var.
• Let’s make use of the let variable:
// let variable
let x; // undefined
let name = 'Mukul’;
// can also declare multiple values
let a=1,b=2,c=3;
// assignment
let a = 3;
a = 4; // works same as var
14-10-2022 31
meghav@kannuruniv.ac.in
Const is another variable type assigned to data whose value
and will not change throughout the script.
// const variable
const name = 'Mukul’;
name = 'Mayank'; // will give Assignment to constant error.
14-10-2022 32
meghav@kannuruniv.ac.in
Variable Scope in Javascript
• Scope of a variable is the part of the program from where the
variable may directly be accessible.
In JavaScript, there are two types of scopes:
1.Global Scope – Scope outside the outermost function attached
to Window.
2.Local Scope – Inside the function being executed.
14-10-2022 33
meghav@kannuruniv.ac.in
JavaScript
let globalVar = "This is a global variable";
function fun() {
let localVar = "This is a local variable";
console.log(globalVar);
console.log(localVar);
}
fun();
14-10-2022 34
meghav@kannuruniv.ac.in
Output
14-10-2022 35
meghav@kannuruniv.ac.in
• When we execute the function fun(), the output shows that both
global, and local variables, are accessible inside the function as
we are able to console.log them.
• This shows that inside the function we have access to both
global variables (declared outside the function) and local
variables (declared inside the function).
• Let’s move the console.log statements outside the function and
put them just after calling the function.
14-10-2022 36
meghav@kannuruniv.ac.in
JavaScript
let globalVar = "This is a global variable";
function fun() {
let localVar = "This is a local variable";
}
fun();
console.log(globalVar);
console.log(localVar);
14-10-2022 37
meghav@kannuruniv.ac.in
Output
14-10-2022 38
meghav@kannuruniv.ac.in
• We are still able to see the value of the global variable, but for
the local variable, console.log throws an error.
• This is because now the console.log statements are present in
global scope where they have access to global variables but
cannot access the local variables.
• Also, any variable defined in a function with the same name as
a global variable takes precedence over the global variable,
shadowing it.
14-10-2022 39
meghav@kannuruniv.ac.in
Reference
1. Jeffrey C. Jackson, Web Technologies: A Computer Science Perspective, Prentice Hall
2. David Flanagan, JavaScript: The Definitive Guide, 6th Edn. O'Reilly Media.2011
3. Bob Breedlove, et al, Web Programming Unleashed, Sams Net Publishing, 1stEdn
4. Steven Holzner, PHP: The Complete Reference, McGraw Hill Professional, 2008
5. Steve Suehring, Tim Converse, Joyce Park, PHP6 and MY SQL Bible, John Wiley & Sons,2009
6. Pedro Teixeira, Instant Node.js Starter, Packt Publishing Ltd., 2013
7. Anthony T. HoldenerIII, Ajax: The Definitive Guide, O’Reilly Media, 2008
8. Nirav Mehta, Choosing an Open Source CMS: Beginner's Guide Packt Publishing Ltd, 2009
9. James Snell, Programming Web Services with SOAP, O'Reilly 2002
10. Jacob Lett , Bootstrap Reference Guide, Bootstrap Creative 2018
11. Maximilian Schwarzmüller, Progressive Web Apps (PWA) - The Complete Guide, Packt Publishing
2018
12. Mahesh Panhale, Beginning Hybrid Mobile Application Development, Apress 2016
14-10-2022 40
meghav@kannuruniv.ac.in

More Related Content

What's hot

Basic JavaScript Tutorial
Basic JavaScript TutorialBasic JavaScript Tutorial
Basic JavaScript TutorialDHTMLExtreme
 
JavaScript Tutorial
JavaScript  TutorialJavaScript  Tutorial
JavaScript TutorialBui Kiet
 
Java script final presentation
Java script final presentationJava script final presentation
Java script final presentationAdhoura Academy
 
Introduction to JavaScript (1).ppt
Introduction to JavaScript (1).pptIntroduction to JavaScript (1).ppt
Introduction to JavaScript (1).pptMuhammadRehan856177
 
Javascript variables and datatypes
Javascript variables and datatypesJavascript variables and datatypes
Javascript variables and datatypesVarun C M
 
Object Oriented Programming In JavaScript
Object Oriented Programming In JavaScriptObject Oriented Programming In JavaScript
Object Oriented Programming In JavaScriptForziatech
 
JavaScript with Syntax & Implementation
JavaScript with Syntax & ImplementationJavaScript with Syntax & Implementation
JavaScript with Syntax & ImplementationSoumen Santra
 
JavaScript Programming
JavaScript ProgrammingJavaScript Programming
JavaScript ProgrammingSehwan Noh
 
Angular - Chapter 4 - Data and Event Handling
 Angular - Chapter 4 - Data and Event Handling Angular - Chapter 4 - Data and Event Handling
Angular - Chapter 4 - Data and Event HandlingWebStackAcademy
 
TypeScript: coding JavaScript without the pain
TypeScript: coding JavaScript without the painTypeScript: coding JavaScript without the pain
TypeScript: coding JavaScript without the painSander Mak (@Sander_Mak)
 
JavaScript Tutorial For Beginners | JavaScript Training | JavaScript Programm...
JavaScript Tutorial For Beginners | JavaScript Training | JavaScript Programm...JavaScript Tutorial For Beginners | JavaScript Training | JavaScript Programm...
JavaScript Tutorial For Beginners | JavaScript Training | JavaScript Programm...Edureka!
 

What's hot (20)

Basic JavaScript Tutorial
Basic JavaScript TutorialBasic JavaScript Tutorial
Basic JavaScript Tutorial
 
Java script
Java scriptJava script
Java script
 
Javascript
JavascriptJavascript
Javascript
 
Html training slide
Html training slideHtml training slide
Html training slide
 
Basics of JavaScript
Basics of JavaScriptBasics of JavaScript
Basics of JavaScript
 
JavaScript Tutorial
JavaScript  TutorialJavaScript  Tutorial
JavaScript Tutorial
 
Java script basics
Java script basicsJava script basics
Java script basics
 
Introduction to JavaScript Basics.
Introduction to JavaScript Basics.Introduction to JavaScript Basics.
Introduction to JavaScript Basics.
 
Java script final presentation
Java script final presentationJava script final presentation
Java script final presentation
 
Introduction to JavaScript (1).ppt
Introduction to JavaScript (1).pptIntroduction to JavaScript (1).ppt
Introduction to JavaScript (1).ppt
 
Javascript by geetanjali
Javascript by geetanjaliJavascript by geetanjali
Javascript by geetanjali
 
Javascript variables and datatypes
Javascript variables and datatypesJavascript variables and datatypes
Javascript variables and datatypes
 
Object Oriented Programming In JavaScript
Object Oriented Programming In JavaScriptObject Oriented Programming In JavaScript
Object Oriented Programming In JavaScript
 
JavaScript with Syntax & Implementation
JavaScript with Syntax & ImplementationJavaScript with Syntax & Implementation
JavaScript with Syntax & Implementation
 
JavaScript Programming
JavaScript ProgrammingJavaScript Programming
JavaScript Programming
 
Angular - Chapter 4 - Data and Event Handling
 Angular - Chapter 4 - Data and Event Handling Angular - Chapter 4 - Data and Event Handling
Angular - Chapter 4 - Data and Event Handling
 
TypeScript: coding JavaScript without the pain
TypeScript: coding JavaScript without the painTypeScript: coding JavaScript without the pain
TypeScript: coding JavaScript without the pain
 
Javascript tutorial
Javascript tutorialJavascript tutorial
Javascript tutorial
 
JavaScript Tutorial For Beginners | JavaScript Training | JavaScript Programm...
JavaScript Tutorial For Beginners | JavaScript Training | JavaScript Programm...JavaScript Tutorial For Beginners | JavaScript Training | JavaScript Programm...
JavaScript Tutorial For Beginners | JavaScript Training | JavaScript Programm...
 
jQuery for beginners
jQuery for beginnersjQuery for beginners
jQuery for beginners
 

Similar to Introduction to JavaScript

Full Stack Web Development
Full Stack Web DevelopmentFull Stack Web Development
Full Stack Web DevelopmentSWAGATHCHOWDARY1
 
Meetup. Technologies Intro for Non-Tech People
Meetup. Technologies Intro for Non-Tech PeopleMeetup. Technologies Intro for Non-Tech People
Meetup. Technologies Intro for Non-Tech PeopleIT Arena
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScriptAndres Baravalle
 
JS BASICS JAVA SCRIPT SCRIPTING
JS BASICS JAVA SCRIPT SCRIPTINGJS BASICS JAVA SCRIPT SCRIPTING
JS BASICS JAVA SCRIPT SCRIPTINGArulkumar
 
Hsc IT Chap 3. Advanced javascript-1.pdf
Hsc IT Chap 3. Advanced javascript-1.pdfHsc IT Chap 3. Advanced javascript-1.pdf
Hsc IT Chap 3. Advanced javascript-1.pdfAAFREEN SHAIKH
 
Skills Required For Full Stack Developer.pdf
Skills Required For Full Stack Developer.pdfSkills Required For Full Stack Developer.pdf
Skills Required For Full Stack Developer.pdfUncodemy
 
DOT NET TRaining
DOT NET TRainingDOT NET TRaining
DOT NET TRainingsunil kumar
 
C# vs Java What are The Differences.pdf
C# vs Java What are The Differences.pdfC# vs Java What are The Differences.pdf
C# vs Java What are The Differences.pdfchristiemarie4
 
INDUSTRIAL TRAINING Presentation on Web Development. (2).pptx
INDUSTRIAL TRAINING Presentation on Web Development. (2).pptxINDUSTRIAL TRAINING Presentation on Web Development. (2).pptx
INDUSTRIAL TRAINING Presentation on Web Development. (2).pptx12KritiGaneriwal
 
Demo Lecture 01 Notes.pptx by Sabki Kaksha
Demo Lecture 01 Notes.pptx by Sabki KakshaDemo Lecture 01 Notes.pptx by Sabki Kaksha
Demo Lecture 01 Notes.pptx by Sabki KakshaGandhiSarthak
 
Demo Lecture 01 Notes paid , course notes
Demo Lecture 01 Notes paid , course notesDemo Lecture 01 Notes paid , course notes
Demo Lecture 01 Notes paid , course notesGandhiSarthak
 
Web-Development-ppt (1).pptx
Web-Development-ppt (1).pptxWeb-Development-ppt (1).pptx
Web-Development-ppt (1).pptxRaihanUddin57
 
Product Camp Silicon Valley 2018 - PM Technical Skills
Product Camp Silicon Valley 2018 - PM Technical SkillsProduct Camp Silicon Valley 2018 - PM Technical Skills
Product Camp Silicon Valley 2018 - PM Technical SkillsSandeep Adwankar
 

Similar to Introduction to JavaScript (20)

Full Stack Web Development
Full Stack Web DevelopmentFull Stack Web Development
Full Stack Web Development
 
Meetup. Technologies Intro for Non-Tech People
Meetup. Technologies Intro for Non-Tech PeopleMeetup. Technologies Intro for Non-Tech People
Meetup. Technologies Intro for Non-Tech People
 
MERN PPT
MERN PPTMERN PPT
MERN PPT
 
Comp102 lec 3
Comp102   lec 3Comp102   lec 3
Comp102 lec 3
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
 
JS BASICS JAVA SCRIPT SCRIPTING
JS BASICS JAVA SCRIPT SCRIPTINGJS BASICS JAVA SCRIPT SCRIPTING
JS BASICS JAVA SCRIPT SCRIPTING
 
Javascript 01 (js)
Javascript 01 (js)Javascript 01 (js)
Javascript 01 (js)
 
Hsc IT Chap 3. Advanced javascript-1.pdf
Hsc IT Chap 3. Advanced javascript-1.pdfHsc IT Chap 3. Advanced javascript-1.pdf
Hsc IT Chap 3. Advanced javascript-1.pdf
 
Java for C++ programers
Java for C++ programersJava for C++ programers
Java for C++ programers
 
Skills Required For Full Stack Developer.pdf
Skills Required For Full Stack Developer.pdfSkills Required For Full Stack Developer.pdf
Skills Required For Full Stack Developer.pdf
 
Software Engineering 2014
Software Engineering 2014Software Engineering 2014
Software Engineering 2014
 
DOT NET TRaining
DOT NET TRainingDOT NET TRaining
DOT NET TRaining
 
Apache Drill (ver. 0.2)
Apache Drill (ver. 0.2)Apache Drill (ver. 0.2)
Apache Drill (ver. 0.2)
 
C# vs Java What are The Differences.pdf
C# vs Java What are The Differences.pdfC# vs Java What are The Differences.pdf
C# vs Java What are The Differences.pdf
 
INDUSTRIAL TRAINING Presentation on Web Development. (2).pptx
INDUSTRIAL TRAINING Presentation on Web Development. (2).pptxINDUSTRIAL TRAINING Presentation on Web Development. (2).pptx
INDUSTRIAL TRAINING Presentation on Web Development. (2).pptx
 
Demo Lecture 01 Notes.pptx by Sabki Kaksha
Demo Lecture 01 Notes.pptx by Sabki KakshaDemo Lecture 01 Notes.pptx by Sabki Kaksha
Demo Lecture 01 Notes.pptx by Sabki Kaksha
 
Demo Lecture 01 Notes paid , course notes
Demo Lecture 01 Notes paid , course notesDemo Lecture 01 Notes paid , course notes
Demo Lecture 01 Notes paid , course notes
 
Web-Development-ppt (1).pptx
Web-Development-ppt (1).pptxWeb-Development-ppt (1).pptx
Web-Development-ppt (1).pptx
 
Beginners Node.js
Beginners Node.jsBeginners Node.js
Beginners Node.js
 
Product Camp Silicon Valley 2018 - PM Technical Skills
Product Camp Silicon Valley 2018 - PM Technical SkillsProduct Camp Silicon Valley 2018 - PM Technical Skills
Product Camp Silicon Valley 2018 - PM Technical Skills
 

More from Megha V

Soft Computing Techniques_Part 1.pptx
Soft Computing Techniques_Part 1.pptxSoft Computing Techniques_Part 1.pptx
Soft Computing Techniques_Part 1.pptxMegha V
 
JavaScript- Functions and arrays.pptx
JavaScript- Functions and arrays.pptxJavaScript- Functions and arrays.pptx
JavaScript- Functions and arrays.pptxMegha V
 
Python Exception Handling
Python Exception HandlingPython Exception Handling
Python Exception HandlingMegha V
 
Python- Regular expression
Python- Regular expressionPython- Regular expression
Python- Regular expressionMegha V
 
File handling in Python
File handling in PythonFile handling in Python
File handling in PythonMegha V
 
Python programming -Tuple and Set Data type
Python programming -Tuple and Set Data typePython programming -Tuple and Set Data type
Python programming -Tuple and Set Data typeMegha V
 
Python programming –part 7
Python programming –part 7Python programming –part 7
Python programming –part 7Megha V
 
Python programming Part -6
Python programming Part -6Python programming Part -6
Python programming Part -6Megha V
 
Python programming: Anonymous functions, String operations
Python programming: Anonymous functions, String operationsPython programming: Anonymous functions, String operations
Python programming: Anonymous functions, String operationsMegha V
 
Python programming- Part IV(Functions)
Python programming- Part IV(Functions)Python programming- Part IV(Functions)
Python programming- Part IV(Functions)Megha V
 
Python programming –part 3
Python programming –part 3Python programming –part 3
Python programming –part 3Megha V
 
Parts of python programming language
Parts of python programming languageParts of python programming language
Parts of python programming languageMegha V
 
Python programming
Python programmingPython programming
Python programmingMegha V
 
Strassen's matrix multiplication
Strassen's matrix multiplicationStrassen's matrix multiplication
Strassen's matrix multiplicationMegha V
 
Solving recurrences
Solving recurrencesSolving recurrences
Solving recurrencesMegha V
 
Algorithm Analysis
Algorithm AnalysisAlgorithm Analysis
Algorithm AnalysisMegha V
 
Algorithm analysis and design
Algorithm analysis and designAlgorithm analysis and design
Algorithm analysis and designMegha V
 
Genetic algorithm
Genetic algorithmGenetic algorithm
Genetic algorithmMegha V
 
UGC NET Paper 1 ICT Memory and data
UGC NET Paper 1 ICT Memory and data  UGC NET Paper 1 ICT Memory and data
UGC NET Paper 1 ICT Memory and data Megha V
 
Seminar presentation on OpenGL
Seminar presentation on OpenGLSeminar presentation on OpenGL
Seminar presentation on OpenGLMegha V
 

More from Megha V (20)

Soft Computing Techniques_Part 1.pptx
Soft Computing Techniques_Part 1.pptxSoft Computing Techniques_Part 1.pptx
Soft Computing Techniques_Part 1.pptx
 
JavaScript- Functions and arrays.pptx
JavaScript- Functions and arrays.pptxJavaScript- Functions and arrays.pptx
JavaScript- Functions and arrays.pptx
 
Python Exception Handling
Python Exception HandlingPython Exception Handling
Python Exception Handling
 
Python- Regular expression
Python- Regular expressionPython- Regular expression
Python- Regular expression
 
File handling in Python
File handling in PythonFile handling in Python
File handling in Python
 
Python programming -Tuple and Set Data type
Python programming -Tuple and Set Data typePython programming -Tuple and Set Data type
Python programming -Tuple and Set Data type
 
Python programming –part 7
Python programming –part 7Python programming –part 7
Python programming –part 7
 
Python programming Part -6
Python programming Part -6Python programming Part -6
Python programming Part -6
 
Python programming: Anonymous functions, String operations
Python programming: Anonymous functions, String operationsPython programming: Anonymous functions, String operations
Python programming: Anonymous functions, String operations
 
Python programming- Part IV(Functions)
Python programming- Part IV(Functions)Python programming- Part IV(Functions)
Python programming- Part IV(Functions)
 
Python programming –part 3
Python programming –part 3Python programming –part 3
Python programming –part 3
 
Parts of python programming language
Parts of python programming languageParts of python programming language
Parts of python programming language
 
Python programming
Python programmingPython programming
Python programming
 
Strassen's matrix multiplication
Strassen's matrix multiplicationStrassen's matrix multiplication
Strassen's matrix multiplication
 
Solving recurrences
Solving recurrencesSolving recurrences
Solving recurrences
 
Algorithm Analysis
Algorithm AnalysisAlgorithm Analysis
Algorithm Analysis
 
Algorithm analysis and design
Algorithm analysis and designAlgorithm analysis and design
Algorithm analysis and design
 
Genetic algorithm
Genetic algorithmGenetic algorithm
Genetic algorithm
 
UGC NET Paper 1 ICT Memory and data
UGC NET Paper 1 ICT Memory and data  UGC NET Paper 1 ICT Memory and data
UGC NET Paper 1 ICT Memory and data
 
Seminar presentation on OpenGL
Seminar presentation on OpenGLSeminar presentation on OpenGL
Seminar presentation on OpenGL
 

Recently uploaded

Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
Science&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfScience&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfjimielynbastida
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsPrecisely
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Neo4j
 

Recently uploaded (20)

Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
Science&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfScience&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdf
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort ServiceHot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power Systems
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024
 

Introduction to JavaScript

  • 1. JavaScript Megha V Asst. Professor Dept. of IT Kannur University 14-10-2022 1 meghav@kannuruniv.ac.in
  • 2. Introduction to JavaScript • JavaScript is a lightweight, cross-platform, and interpreted compiled programming language which is also known as the scripting language for webpages. • It is well-known for the development of web pages, many non-browser environments also use it. • A scripting language is a programming language that employs a high-level construct to interpret and execute one command at a time. • In general, scripting languages are easier to learn and faster to code in than more structured and compiled languages such as C and C++. 14-10-2022 2 meghav@kannuruniv.ac.in
  • 3. Introduction to JavaScript • JavaScript can be used for Client-side developments as well as Server-side developments. Client-side Programming : • It is the program that runs on the client machine (browser) and deals with the user interface/display and any other processing that can happen on client machine like reading/writing cookies. 1) Interact with temporary storage 2) Make interactive web pages 3) Interact with local storage 4) Sending request for data to server 5) Send request to server 6) work as an interface between server and user 14-10-2022 3 meghav@kannuruniv.ac.in
  • 4. • The Programming languages for client-side programming are : 1) JavaScript 2) VBScript 3) HTML 4) CSS 5) AJAX 14-10-2022 4 meghav@kannuruniv.ac.in
  • 5. Server-side Programming : • It is the program that runs on server dealing with the generation of content of web page. 1) Querying the database 2) Operations over databases 3) Access/Write a file on server. 4) Interact with other servers. 5) Structure web applications. 6) Process user input. • For example if user input is a text in search box, run a search algorithm on data stored on server and send the results. 14-10-2022 5 meghav@kannuruniv.ac.in
  • 6. • Examples : The Programming languages for server-side programming are : 1) PHP 2) C++ 3) Java and JSP 4) Python 5) Ruby on Rails 14-10-2022 6 meghav@kannuruniv.ac.in
  • 7. • Javascript is both imperative and declarative type of language. • JavaScript contains a standard library of objects, like Array, Date, and Math, and a core set of language elements like operators, control structures, and statements. 14-10-2022 7 meghav@kannuruniv.ac.in
  • 8. Client-side: • It supplies objects to control a browser and its Document Object Model (DOM). • When a web page is loaded, the browser creates a Document Object Model of the page. The HTML DOM is a standard object model and programming interface for HTML. It defines: • The HTML elements as objects • The properties of all HTML elements • The methods to access all HTML elements • The events for all HTML elements 14-10-2022 8 meghav@kannuruniv.ac.in
  • 9. • Like if client-side extensions allow an application to place elements on an HTML form and respond to user events such as mouse clicks, form input, and page navigation. • Useful libraries for the client-side are AngularJS, ReactJS, VueJS and so many others. 14-10-2022 meghav@kannuruniv.ac.in 9
  • 10. Server-side: • It supplies objects relevant to running JavaScript on a server. • Like if the server-side extensions allow an application to communicate with a database, and provide continuity of information from one invocation to another of the application, or perform file manipulations on a server. • The useful framework which is the most famous these days is node.js. 14-10-2022 10 meghav@kannuruniv.ac.in
  • 11. Imperative language • In this type of language we are mostly concern about how it is to be done. • It simply control the flow of computation . • The procedural programming approach , object, oriented approach comes under this. 14-10-2022 11 meghav@kannuruniv.ac.in
  • 12. Declarative programming – • In this type of language we are concern about how it is to be done , basically here logical computation require . • Here main goal is to describe the desired result without direct dictation on how to get it like arrow function do. 14-10-2022 12 meghav@kannuruniv.ac.in
  • 13. JavaScript can be added to your HTML file in two ways: • Internal JS: We can add JavaScript directly to our HTML file by writing the code inside the <script> tag. • The <script> tag can either be placed inside the <head> or the <body> tag according to the requirement. • External JS: We can write JavaScript code in other file having an extension .js and then link this file inside the <head> tag of the HTML file in which we want to add this code. 14-10-2022 13 meghav@kannuruniv.ac.in
  • 15. Example: <!DOCTYPE html> <html lang="en"> <head> <title> Basic Example to Describe JavaScript </title> </head> <body> <!-- JavaScript code can be embedded inside head section or body section --> <script> console.log("Welcome to GeeksforGeeks"); </script> </body> </html> 14-10-2022 15 meghav@kannuruniv.ac.in
  • 16. External JS function myFunction() { document.getElementById("demo").innerHTML = "Paragraph changed."; } • External scripts are practical when the same code is used in many different web pages. • JavaScript files have the file extension .js. • To use an external script, put the name of the script file in the src (source) attribute of a <script> tag: <script src="myScript.js"></script> 14-10-2022 meghav@kannuruniv.ac.in 16
  • 17. History of JavaScript: • It was created in 1995 by Brendan Eich while he was an engineer at Netscape. • It was originally going to be named LiveScript but was renamed. • Unlike most programming languages, the JavaScript language has no concept of input or output. • It is designed to run as a scripting language in a host environment, and it is up to the host environment to provide mechanisms for communicating with the outside world. • The most common host environment is the browser. 14-10-2022 17 meghav@kannuruniv.ac.in
  • 18. Features of JavaScript: • According to a recent survey conducted by Stack Overflow, JavaScript is the most popular language on earth. • With advances in browser technology and JavaScript having moved into the server with Node.js and other frameworks, JavaScript is capable of so much more. • Here are a few things that we can do with JavaScript: 14-10-2022 18 meghav@kannuruniv.ac.in
  • 19. • JavaScript was created in the first place for DOM manipulation. • Earlier websites were mostly static, after JS was created dynamic Web sites were made. • Functions in JS are objects. • They may have properties and methods just like another object. • They can be passed as arguments in other functions. • Can handle date and time. • Performs Form Validation although the forms are created using HTML. • No compiler is needed. 14-10-2022 19 meghav@kannuruniv.ac.in
  • 20. Variables and Datatypes in JavaScript Datatypes in JavaScript • There are majorly two types of languages. • First, one is Statically typed language where each variable and expression type is already known at compile time. • Once a variable is declared to be of a certain data type, it cannot hold values of other data types. • Example: C, C++, Java. 14-10-2022 20 meghav@kannuruniv.ac.in
  • 21. // Java(Statically typed) int x = 5 // variable x is of type int and it will not store any other type. string y = 'abc' // type string and will only accept string values Other, Dynamically typed languages: These languages can receive different data types over time. For example- Ruby, Python, JavaScript, etc. // Javascript(Dynamically typed) var x = 5; // can store an integer var name = 'string'; // can also store a string. 14-10-2022 21 meghav@kannuruniv.ac.in
  • 22. • JavaScript is a dynamically typed (also called loosely typed) scripting language. • That is, in JavaScript variables can receive different data types over time. • Datatypes are basically typed data that can be used and manipulated in a program. 14-10-2022 22 meghav@kannuruniv.ac.in
  • 23. • The latest ECMAScript(ES6)-European Computer Manufacturers Association Script standard defines following data types: • Out of which six data types are Primitive(predefined). •Numbers: Represent both integer and floating-point numbers. Example: 5, 6.5, 7 etc. •String: A string is a sequence of characters. In JavaScript, strings can be enclosed within the single or double quotes. Example: “Hello GeeksforGeeks” etc. •Boolean: Represent a logical entity and can have two values: true or false. •Null: This type has only one value : null. •Undefined: A variable that has not been assigned a value is undefined. 14-10-2022 23 meghav@kannuruniv.ac.in
  • 24. • Symbol: Unlike other primitive data types, it does not have any literal form. • It is a built-in object whose constructor returns a symbol-that is unique. • bigint: The bigint type represents the whole numbers that are larger than 253-1. • To form a bigint literal number, you append the letter n at the end of the number. • Object: It is the most important data-type and forms the building blocks for modern JavaScript. 14-10-2022 24 meghav@kannuruniv.ac.in
  • 25. Variables in JavaScript: • Variables in JavaScript are containers that hold reusable data. It is the basic unit of storage in a program. • The value stored in a variable can be changed during program execution. • A variable is only a name given to a memory location, all the operations done on the variable effects that memory location. • In JavaScript, all the variables must be declared before they can be used. 14-10-2022 25 meghav@kannuruniv.ac.in
  • 26. • Before ES2015, JavaScript variables were solely declared using the var keyword followed by the name of the variable and semi-colon. • Below is the syntax to create variables in JavaScript: var var_name; var x; • The var_name is the name of the variable which should be defined by the user and should be unique. • These types of names are also known as identifiers. 14-10-2022 26 meghav@kannuruniv.ac.in
  • 27. • The rules for creating an identifier in JavaScript are, the name of the identifier should not be any pre-defined word(known as keywords), the first character must be a letter, an underscore (_), or a dollar sign ($). • Subsequent characters may be any letter or digit or an underscore or dollar sign. • Notice in the above code sample, we didn’t assign any values to the variables. We are only saying they exist. If you were to look at the value of each variable in the above code sample, it would be undefined. • We can initialize the variables either at the time of declaration or also later when we want to use them. 14-10-2022 27 meghav@kannuruniv.ac.in
  • 28. Below are some examples of declaring and initializing variables in JavaScript: // declaring single variable var name; // declaring multiple variables var name, title, num; // initializing variables var name = "Harsh"; name = “Anu"; 14-10-2022 28 meghav@kannuruniv.ac.in
  • 29. JavaScript is also known as untyped language. This means, that once a variable is created in JavaScript using the keyword var, we can store any type of value in this variable supported by JavaScript. Below is the example for this: // creating variable to store a number var num = 5; // store string in the variable num num = "GeeksforGeeks"; 14-10-2022 29 meghav@kannuruniv.ac.in
  • 30. • The above example executes well without any error in JavaScr unlike other programming languages. • Variables in JavaScript can also evaluate simple mathematical expressions and assume their value. // storing a mathematical expression var x = 5 + 10 + 1; console.log(x); // 16 14-10-2022 30 meghav@kannuruniv.ac.in
  • 31. • After ES2015, we now have two new variable containers: let and const. • The variable type Let shares lots of similarities with var but unlike var, it has scope constraints. • To know more about them visit let vs var. • Let’s make use of the let variable: // let variable let x; // undefined let name = 'Mukul’; // can also declare multiple values let a=1,b=2,c=3; // assignment let a = 3; a = 4; // works same as var 14-10-2022 31 meghav@kannuruniv.ac.in
  • 32. Const is another variable type assigned to data whose value and will not change throughout the script. // const variable const name = 'Mukul’; name = 'Mayank'; // will give Assignment to constant error. 14-10-2022 32 meghav@kannuruniv.ac.in
  • 33. Variable Scope in Javascript • Scope of a variable is the part of the program from where the variable may directly be accessible. In JavaScript, there are two types of scopes: 1.Global Scope – Scope outside the outermost function attached to Window. 2.Local Scope – Inside the function being executed. 14-10-2022 33 meghav@kannuruniv.ac.in
  • 34. JavaScript let globalVar = "This is a global variable"; function fun() { let localVar = "This is a local variable"; console.log(globalVar); console.log(localVar); } fun(); 14-10-2022 34 meghav@kannuruniv.ac.in
  • 36. • When we execute the function fun(), the output shows that both global, and local variables, are accessible inside the function as we are able to console.log them. • This shows that inside the function we have access to both global variables (declared outside the function) and local variables (declared inside the function). • Let’s move the console.log statements outside the function and put them just after calling the function. 14-10-2022 36 meghav@kannuruniv.ac.in
  • 37. JavaScript let globalVar = "This is a global variable"; function fun() { let localVar = "This is a local variable"; } fun(); console.log(globalVar); console.log(localVar); 14-10-2022 37 meghav@kannuruniv.ac.in
  • 39. • We are still able to see the value of the global variable, but for the local variable, console.log throws an error. • This is because now the console.log statements are present in global scope where they have access to global variables but cannot access the local variables. • Also, any variable defined in a function with the same name as a global variable takes precedence over the global variable, shadowing it. 14-10-2022 39 meghav@kannuruniv.ac.in
  • 40. Reference 1. Jeffrey C. Jackson, Web Technologies: A Computer Science Perspective, Prentice Hall 2. David Flanagan, JavaScript: The Definitive Guide, 6th Edn. O'Reilly Media.2011 3. Bob Breedlove, et al, Web Programming Unleashed, Sams Net Publishing, 1stEdn 4. Steven Holzner, PHP: The Complete Reference, McGraw Hill Professional, 2008 5. Steve Suehring, Tim Converse, Joyce Park, PHP6 and MY SQL Bible, John Wiley & Sons,2009 6. Pedro Teixeira, Instant Node.js Starter, Packt Publishing Ltd., 2013 7. Anthony T. HoldenerIII, Ajax: The Definitive Guide, O’Reilly Media, 2008 8. Nirav Mehta, Choosing an Open Source CMS: Beginner's Guide Packt Publishing Ltd, 2009 9. James Snell, Programming Web Services with SOAP, O'Reilly 2002 10. Jacob Lett , Bootstrap Reference Guide, Bootstrap Creative 2018 11. Maximilian Schwarzmüller, Progressive Web Apps (PWA) - The Complete Guide, Packt Publishing 2018 12. Mahesh Panhale, Beginning Hybrid Mobile Application Development, Apress 2016 14-10-2022 40 meghav@kannuruniv.ac.in