SlideShare a Scribd company logo
By: Sahil Goel
WHAT IS JAVASCRIPT?
• JavaScript is a scripting language (a scripting language is a lightweight
  programming language)
• JavaScript was designed to add interactivity to HTML pages
• JavaScript is an interpreted language (means that scripts execute without
  preliminary compilation)
• Everyone can use JavaScript without purchasing a license
• JavaScript is used in millions of Web pages to improve the design, validate
  forms, detect browsers, create cookies, and much more.
• JavaScript works in all major browsers, such as Internet
  Explorer, Mozilla, Firefox, Opera.
Where did it come from
• Originally called LiveScript at Netscape started out to be a server side
  scripting language for providing database connectivity and dynamic HTML
  generation on Netscape Web Servers.
• Netscape decided it would be a good thing for their browsers and servers
  to speak the same language so it got included in Navigator.
• Netscape in alliance with Sun jointly announced the language and its new
  name Java Script
• Because of rapid acceptance by the web community Microsoft forced to
  include in IE Browser
Are Java and JavaScript the Same?

NO! Java and JavaScript are two completely different languages
in both concept and design!

   • Java (developed by Sun            • JavaScript (developed by
     Microsystems) is a powerful and     Netscape), is a smaller language
     much more complex                   that does not create applets or
     programming language - in the       standalone applications. In its
     same category as C and C++.         most common form
   • It can be used to create            today, JavaScript resides inside
     standalone applications and a       HTML documents, and can
     special type of mini                provide levels of interactivity far
     application, called an applet.      beyond typically flat HTML pages
How to Put a JavaScript Into an
                                    HTML Page?

We can add JavaScript in three ways in our
document:
1) Inline
<input type="button" id="hello-world2" value="Hello" onClick="alert('Hello World!');" />

2) Embedded
<script type="text/javascript">
function helloWorld() { alert('Hello World!') ; }
</script>

3) External
<head> <script type="text/javascript" language="javascript" src="hello.js"></script></head>
How to Put a JavaScript Into an HTML Page?

                                                    Ending Statements With a Semicolon?
        <html>
                                                  • With traditional programming
        <body>
                                                    languages, like C++ and Java, each code
        <script type="text/javascript">             statement has to end with a semicolon
        document.write("Hello World!");             (;).
        </script>                                 • Many programmers continue this habit
        </body>                                     when writing JavaScript, but in
        </html>                                     general, semicolons are optional!
                                                    However, semicolons are required if you
                                                    want to put more than one statement
                                                    on a single line.
NOTE: At times JavaScript is disabled in some browsers and it becomes difficult to get
appropriate behavior and the user get confused, so to avoid such conditions we should check if
it is enable or we should display an appropriate message. We can do this with the help of:
<noscript> <p>This will not be displayed if JavaScript is enabled</p> </noscript>
JavaScript Terminology

Objects:                                Properties:
• Almost everything in JavaScript       • Properties are object attributes.
   is an Object: String, Number,        • Object properties are defined by
   Array, Function....                     using the object's name, a
• An object is just a special kind of      period, and the property name.
   data, with properties and            • e.g., background color is
   methods.                                expressed by:
• Objects have properties that act         document.bgcolor
   as modifiers.                           document is the object
                                           .bgcolor is the property.
   Eg: personObj=new Object();
   personObj.firstname="John";
   personObj.lastname="Doe";
   personObj.age=50;
   personObj.eyecolor="blue";
JavaScript Terminology
Methods:                             Events:
• Methods are actions applied to     • Events associate an object with
   particular objects. Methods are      an action.
   what objects can do.              e.g., the onclick event handler
e.g.,                                action can change an image.
document.write(”Hello                e.g., the onSubmit event handler
World")                              sends a form.
document is the object.              • User actions trigger events.
write is the method.
JavaScript Terminology
Functions:                            Values:
• Functions are named statements      • Values are bits of information.
    that performs tasks.              • Values, types and some examples
e.g. function doWhatever()                include:
          {                           Number: 1, 2, 3, etc.
             statement here           String: characters enclosed in quotes.
          }                           Boolean: true or false.
The curly braces contain the          Object: image, form
statements of the function.           Function: validate, doWhatever
• JavaScript has built-in
    functions, and we can write our
    own.
JavaScript Terminology
Variables:                           Expressions :
• Variables contain values and use   • Expressions are commands that
   the equal sign to specify their      assign values to variables.
   value.                            • Expressions always use an
• Variables are created by              assignment operator, such as
   declaration using the var            the equals sign.
   command with or without an        e.g., var month = May; is an
   initial value state.              expression.
e.g. var month;
                                     • Expressions end with a
e.g. var month = April;                 semicolon.
JavaScript Terminology
Operators:
• Operators are used to handle variables.
Types of operators with examples:
Arithmetic operators, such as plus(+).
Comparisons operators, such as equals(==).
Logical operators, such as AND.
Assignment like (=).
+ Operator: The + operator can also be used to add string variables or text
values together.
Condition statements
• Very often when we write code, we want to perform different actions
  for different decisions. we can use conditional statements in our code
  to do this.

In JavaScript we have the following conditional statements:
• if statement - use this statement if we want to execute some code only
    if a specified condition is true
• if...else statement - use this statement if we want to execute some
    code if the condition is true and another code if the condition is false
• if...else if....else statement - use this statement if we want to select one
    of many blocks of code to be executed
• switch statement - use this statement if we want to select one of many
    blocks of code to be executed
Loops
JavaScript performs several types of repetitive operations, called "looping".
• for loop: The for loop is executed till a specified condition returns false
for (initialization; condition; increment)
{
   // statements
}
• while loop: The while statement repeats a loop as long as a specified
     condition evaluates to true.
while (condition)
{
  // statements
}
Arrays
Arrays are usually a group of the same variable type that use an index number
to distinguish them from each other. Arrays are one way of keeping a program
more organized.


  Creating arrays:                               Initializing an array:
  •   var badArray = new Array(10);              •   Var myArray= new Array(“January”,” February”,”
      // Creates an empty Array that's sized         March”);
      for 10 elements.                           •   var myArray = ['January', 'February', 'March'];
  •    var goodArray= [10];                          document.write(myArray[0]);//output: January
      //Creates an Array with 10 as the first        document.write(myArray[1]);//output: February
      element.                                       document.write(myArray[2]);//output: March
JavaScript Popup Boxes
It is possible to make three different kinds of
popup boxes:
1) Alert Box
• An alert box is often used if we want to make sure information comes
  through to the user.
• When an alert box pops up, the user will have to click "OK" to proceed.


  <script>
  alert("Hello World")
  </script>
2) Confirm Box
• A confirm box is often used if we want the user to verify or accept
  something.
• When a confirm box pops up, the user will have to click either "OK" or
  "Cancel" to proceed.
• If the user clicks "OK", the box returns true. If the user clicks
  "Cancel", the box returns false.


    <script>
    var r=confirm("Press a button!");
    if (r==true)
    document.write("You pressed OK!“);
    else
    document.write("You pressed Cancel!“);
    </script>
3) Prompt Box
• A prompt box is often used if you want the user to input a value before
  entering a page.
• When a prompt box pops up, the user will have to click either "OK" or
  "Cancel" to proceed after entering an input value.
• If the user clicks "OK“, the box returns the input value. If the user clicks
  "Cancel“, the box returns null.



     <script>
     x=prompt (“Please enter your name”, “sahil goel ”)
     document.write(“Welcome <br>”+x)
     </script>
DOM
• The Document Object Model (DOM) is the model that describes how all
    elements in an HTML page, like input fields, images, paragraphs etc., are
    related to the topmost structure: the document itself. By calling the
    element by its proper DOM name, we can influence it.
• In DOM each object, whatever it may be exactly, is a Node.
Node object: We can traverse through different nodes with the help of certain
node properties and methods:
Eg: firstChild, lastChild, parentNode, nextSibling, previousSibling etc.
Document object:The Document object gives us access to the document's
data. Some document methods are:
Eg: getElementById(), getElementsByTagName() etc.
What is a Cookie?
A cookie is a small text file that JavaScript can use to store information about a user.
• There are two types of cookies:
    – 1) Session Cookies
    – 2) Persistent Cookies
Session Cookies :A browser stores session cookies in memory.
•   Once a browser session ends, browser loses the contents of a session cookie.

–Persistent Cookies: Browsers store persistent cookies to a user’s hard
drive.
• We can use persistent cookies to get information about a user that we can use
    when the user returns to a website at a later date.
More about Cookies
• JavaScript deals with cookies as objects.
• JavaScript works with cookies using the document.cookie
  attribute.

Examples of cookie usage:
• User preferences
• Saving form data
• Tracking online shopping habits
Parts of a Cookie Object
• name – An identifier by which we reference a particular cookie.
• value – The information we wish to save, in reference to a particular
  cookie.
• expires – A GMT-formatted date specifying the date (in milliseconds)
  when a cookie will expire.
• path – Specifies the path of the web server in which the cookie is
  valid. By default, set to the path of the page that set the cookie.
  However, commonly specified to /, the root directory.
• domain – Specifies the domain for which the cookie is valid. Set, by
  default, only to the full domain of a page..
• secure – Specifies that a web browser needs a secure HTTP
  connection to access a cookie.
Setting a Cookie – General Form:
document.cookie = “cookieName = cookieValue;
  expires = expireDate; path = pathName;
      domain = domainName; secure”;


Escape Sequences:
• When we set cookie values, we must first convert the string values that
  set a cookie so that the string doesn’t contain white space, commas or
  semi-colons.
• We can use JavaScript’s intrinsic escape() function to convert white
  space and punctuation with escape sequences.
• Conversely, we can use unescape() to view text encoded with
  escape().
Cookie limitations:

• A given domain may only set 20 cookies per machine.
• A single browser may only store 300 cookies.
• Browsers limit a single cookie to 4KB.
THANK YOU!
Ad

More Related Content

What's hot (20)

Java web application development
Java web application developmentJava web application development
Java web application development
RitikRathaur
 
Solid NodeJS with TypeScript, Jest & NestJS
Solid NodeJS with TypeScript, Jest & NestJSSolid NodeJS with TypeScript, Jest & NestJS
Solid NodeJS with TypeScript, Jest & NestJS
Rafael Casuso Romate
 
TypeScript
TypeScriptTypeScript
TypeScript
Merchu Liang
 
Html5 tutorial for beginners
Html5 tutorial for beginnersHtml5 tutorial for beginners
Html5 tutorial for beginners
Singsys Pte Ltd
 
Advance Java Topics (J2EE)
Advance Java Topics (J2EE)Advance Java Topics (J2EE)
Advance Java Topics (J2EE)
slire
 
Angular - Chapter 9 - Authentication and Authorization
Angular - Chapter 9 - Authentication and AuthorizationAngular - Chapter 9 - Authentication and Authorization
Angular - Chapter 9 - Authentication and Authorization
WebStackAcademy
 
Virtual machine
Virtual machineVirtual machine
Virtual machine
Rinaldo John
 
JAVA-PPT'S.pptx
JAVA-PPT'S.pptxJAVA-PPT'S.pptx
JAVA-PPT'S.pptx
RaazIndia
 
VB Script
VB ScriptVB Script
VB Script
Satish Sukumaran
 
Inheritance in Java
Inheritance in JavaInheritance in Java
Inheritance in Java
Tamanna Akter
 
ASP.NET MVC.
ASP.NET MVC.ASP.NET MVC.
ASP.NET MVC.
Ni
 
JAVA AWT
JAVA AWTJAVA AWT
JAVA AWT
shanmuga rajan
 
Document Object Model
Document Object ModelDocument Object Model
Document Object Model
baabtra.com - No. 1 supplier of quality freshers
 
Client side scripting and server side scripting
Client side scripting and server side scriptingClient side scripting and server side scripting
Client side scripting and server side scripting
baabtra.com - No. 1 supplier of quality freshers
 
Java awt (abstract window toolkit)
Java awt (abstract window toolkit)Java awt (abstract window toolkit)
Java awt (abstract window toolkit)
Elizabeth alexander
 
Decomposition using Functional Dependency
Decomposition using Functional DependencyDecomposition using Functional Dependency
Decomposition using Functional Dependency
Raj Naik
 
ASP.NET Web form
ASP.NET Web formASP.NET Web form
ASP.NET Web form
Md. Mahedee Hasan
 
Java adapter
Java adapterJava adapter
Java adapter
Arati Gadgil
 
MVC Architecture
MVC ArchitectureMVC Architecture
MVC Architecture
Prem Sanil
 
Xml and xml processor
Xml and xml processorXml and xml processor
Xml and xml processor
Himanshu Soni
 

Viewers also liked (6)

JavaScript Missing Manual, Ch. 1
JavaScript Missing Manual, Ch. 1JavaScript Missing Manual, Ch. 1
JavaScript Missing Manual, Ch. 1
Gene Babon
 
Pinned Sites IE 9 Lightup
Pinned Sites IE 9 LightupPinned Sites IE 9 Lightup
Pinned Sites IE 9 Lightup
Wes Yanaga
 
Windows Phone 7 Unleashed Session 1
Windows Phone 7 Unleashed Session 1Windows Phone 7 Unleashed Session 1
Windows Phone 7 Unleashed Session 1
Wes Yanaga
 
Windows Phone 7 Unleashed Session 2
Windows Phone 7 Unleashed Session 2Windows Phone 7 Unleashed Session 2
Windows Phone 7 Unleashed Session 2
Wes Yanaga
 
JAVA SCRIPT
JAVA SCRIPTJAVA SCRIPT
JAVA SCRIPT
Go4Guru
 
Introduction to java_script
Introduction to java_scriptIntroduction to java_script
Introduction to java_script
Basavaraj Hampali
 
JavaScript Missing Manual, Ch. 1
JavaScript Missing Manual, Ch. 1JavaScript Missing Manual, Ch. 1
JavaScript Missing Manual, Ch. 1
Gene Babon
 
Pinned Sites IE 9 Lightup
Pinned Sites IE 9 LightupPinned Sites IE 9 Lightup
Pinned Sites IE 9 Lightup
Wes Yanaga
 
Windows Phone 7 Unleashed Session 1
Windows Phone 7 Unleashed Session 1Windows Phone 7 Unleashed Session 1
Windows Phone 7 Unleashed Session 1
Wes Yanaga
 
Windows Phone 7 Unleashed Session 2
Windows Phone 7 Unleashed Session 2Windows Phone 7 Unleashed Session 2
Windows Phone 7 Unleashed Session 2
Wes Yanaga
 
JAVA SCRIPT
JAVA SCRIPTJAVA SCRIPT
JAVA SCRIPT
Go4Guru
 
Ad

Similar to Java script (20)

Introduction to JAVA SCRIPT USING HTML and CSS
Introduction to JAVA SCRIPT USING HTML and CSSIntroduction to JAVA SCRIPT USING HTML and CSS
Introduction to JAVA SCRIPT USING HTML and CSS
ManasaMR2
 
Java script
Java scriptJava script
Java script
Abhishek Kesharwani
 
JavaScript_III.pptx
JavaScript_III.pptxJavaScript_III.pptx
JavaScript_III.pptx
rashmiisrani1
 
Java Script basics and DOM
Java Script basics and DOMJava Script basics and DOM
Java Script basics and DOM
Sukrit Gupta
 
Final Java-script.pptx
Final Java-script.pptxFinal Java-script.pptx
Final Java-script.pptx
AlkanthiSomesh
 
Javascript
JavascriptJavascript
Javascript
Mozxai
 
WT Unit-3 PPT.pptx
WT Unit-3 PPT.pptxWT Unit-3 PPT.pptx
WT Unit-3 PPT.pptx
TusharTikia
 
JavaScript Fundamentals & JQuery
JavaScript Fundamentals & JQueryJavaScript Fundamentals & JQuery
JavaScript Fundamentals & JQuery
Jamshid Hashimi
 
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
AAFREEN SHAIKH
 
Basics java scripts
Basics java scriptsBasics java scripts
Basics java scripts
ch samaram
 
Java script
Java scriptJava script
Java script
Jay Patel
 
javascriptPresentation.pdf
javascriptPresentation.pdfjavascriptPresentation.pdf
javascriptPresentation.pdf
wildcat9335
 
Javascript Basics by Bonny
Javascript Basics by BonnyJavascript Basics by Bonny
Javascript Basics by Bonny
Bonny Chacko
 
Thinkful - Intro to JavaScript
Thinkful - Intro to JavaScriptThinkful - Intro to JavaScript
Thinkful - Intro to JavaScript
TJ Stalcup
 
Lecture 5 javascript
Lecture 5 javascriptLecture 5 javascript
Lecture 5 javascript
Mujtaba Haider
 
JavaScript with Syntax & Implementation
JavaScript with Syntax & ImplementationJavaScript with Syntax & Implementation
JavaScript with Syntax & Implementation
Soumen Santra
 
Java script
Java scriptJava script
Java script
Rajkiran Mummadi
 
Intro to JavaScript - Thinkful LA, June 2017
Intro to JavaScript - Thinkful LA, June 2017Intro to JavaScript - Thinkful LA, June 2017
Intro to JavaScript - Thinkful LA, June 2017
Thinkful
 
WEB TECHNOLOGIES JavaScript
WEB TECHNOLOGIES JavaScriptWEB TECHNOLOGIES JavaScript
WEB TECHNOLOGIES JavaScript
Jyothishmathi Institute of Technology and Science Karimnagar
 
Learning space presentation1 learn Java script
Learning space presentation1 learn Java scriptLearning space presentation1 learn Java script
Learning space presentation1 learn Java script
engmk83
 
Introduction to JAVA SCRIPT USING HTML and CSS
Introduction to JAVA SCRIPT USING HTML and CSSIntroduction to JAVA SCRIPT USING HTML and CSS
Introduction to JAVA SCRIPT USING HTML and CSS
ManasaMR2
 
Java Script basics and DOM
Java Script basics and DOMJava Script basics and DOM
Java Script basics and DOM
Sukrit Gupta
 
Final Java-script.pptx
Final Java-script.pptxFinal Java-script.pptx
Final Java-script.pptx
AlkanthiSomesh
 
Javascript
JavascriptJavascript
Javascript
Mozxai
 
WT Unit-3 PPT.pptx
WT Unit-3 PPT.pptxWT Unit-3 PPT.pptx
WT Unit-3 PPT.pptx
TusharTikia
 
JavaScript Fundamentals & JQuery
JavaScript Fundamentals & JQueryJavaScript Fundamentals & JQuery
JavaScript Fundamentals & JQuery
Jamshid Hashimi
 
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
AAFREEN SHAIKH
 
Basics java scripts
Basics java scriptsBasics java scripts
Basics java scripts
ch samaram
 
javascriptPresentation.pdf
javascriptPresentation.pdfjavascriptPresentation.pdf
javascriptPresentation.pdf
wildcat9335
 
Javascript Basics by Bonny
Javascript Basics by BonnyJavascript Basics by Bonny
Javascript Basics by Bonny
Bonny Chacko
 
Thinkful - Intro to JavaScript
Thinkful - Intro to JavaScriptThinkful - Intro to JavaScript
Thinkful - Intro to JavaScript
TJ Stalcup
 
JavaScript with Syntax & Implementation
JavaScript with Syntax & ImplementationJavaScript with Syntax & Implementation
JavaScript with Syntax & Implementation
Soumen Santra
 
Intro to JavaScript - Thinkful LA, June 2017
Intro to JavaScript - Thinkful LA, June 2017Intro to JavaScript - Thinkful LA, June 2017
Intro to JavaScript - Thinkful LA, June 2017
Thinkful
 
Learning space presentation1 learn Java script
Learning space presentation1 learn Java scriptLearning space presentation1 learn Java script
Learning space presentation1 learn Java script
engmk83
 
Ad

More from Sukrit Gupta (8)

C Language - Switch and For Loop
C Language - Switch and For LoopC Language - Switch and For Loop
C Language - Switch and For Loop
Sukrit Gupta
 
The n Queen Problem
The n Queen ProblemThe n Queen Problem
The n Queen Problem
Sukrit Gupta
 
Future Technologies - Integral Cord
Future Technologies - Integral CordFuture Technologies - Integral Cord
Future Technologies - Integral Cord
Sukrit Gupta
 
Harmful Effect Of Computers On Environment - EWASTE
Harmful Effect Of Computers On Environment - EWASTE Harmful Effect Of Computers On Environment - EWASTE
Harmful Effect Of Computers On Environment - EWASTE
Sukrit Gupta
 
MySql
MySqlMySql
MySql
Sukrit Gupta
 
Html n CSS
Html n CSSHtml n CSS
Html n CSS
Sukrit Gupta
 
Html and css
Html and cssHtml and css
Html and css
Sukrit Gupta
 
Cookies and sessions
Cookies and sessionsCookies and sessions
Cookies and sessions
Sukrit Gupta
 
C Language - Switch and For Loop
C Language - Switch and For LoopC Language - Switch and For Loop
C Language - Switch and For Loop
Sukrit Gupta
 
The n Queen Problem
The n Queen ProblemThe n Queen Problem
The n Queen Problem
Sukrit Gupta
 
Future Technologies - Integral Cord
Future Technologies - Integral CordFuture Technologies - Integral Cord
Future Technologies - Integral Cord
Sukrit Gupta
 
Harmful Effect Of Computers On Environment - EWASTE
Harmful Effect Of Computers On Environment - EWASTE Harmful Effect Of Computers On Environment - EWASTE
Harmful Effect Of Computers On Environment - EWASTE
Sukrit Gupta
 
Cookies and sessions
Cookies and sessionsCookies and sessions
Cookies and sessions
Sukrit Gupta
 

Recently uploaded (20)

The History of Kashmir Karkota Dynasty NEP.pptx
The History of Kashmir Karkota Dynasty NEP.pptxThe History of Kashmir Karkota Dynasty NEP.pptx
The History of Kashmir Karkota Dynasty NEP.pptx
Arya Mahila P. G. College, Banaras Hindu University, Varanasi, India.
 
CNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscessCNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscess
Mohamed Rizk Khodair
 
PHYSIOLOGY MCQS By DR. NASIR MUSTAFA (PHYSIOLOGY)
PHYSIOLOGY MCQS By DR. NASIR MUSTAFA (PHYSIOLOGY)PHYSIOLOGY MCQS By DR. NASIR MUSTAFA (PHYSIOLOGY)
PHYSIOLOGY MCQS By DR. NASIR MUSTAFA (PHYSIOLOGY)
Dr. Nasir Mustafa
 
dynastic art of the Pallava dynasty south India
dynastic art of the Pallava dynasty south Indiadynastic art of the Pallava dynasty south India
dynastic art of the Pallava dynasty south India
PrachiSontakke5
 
How to Manage Purchase Alternatives in Odoo 18
How to Manage Purchase Alternatives in Odoo 18How to Manage Purchase Alternatives in Odoo 18
How to Manage Purchase Alternatives in Odoo 18
Celine George
 
Cultivation Practice of Garlic in Nepal.pptx
Cultivation Practice of Garlic in Nepal.pptxCultivation Practice of Garlic in Nepal.pptx
Cultivation Practice of Garlic in Nepal.pptx
UmeshTimilsina1
 
Computer crime and Legal issues Computer crime and Legal issues
Computer crime and Legal issues Computer crime and Legal issuesComputer crime and Legal issues Computer crime and Legal issues
Computer crime and Legal issues Computer crime and Legal issues
Abhijit Bodhe
 
How to Configure Public Holidays & Mandatory Days in Odoo 18
How to Configure Public Holidays & Mandatory Days in Odoo 18How to Configure Public Holidays & Mandatory Days in Odoo 18
How to Configure Public Holidays & Mandatory Days in Odoo 18
Celine George
 
Grade 3 - English - Printable Worksheet (PDF Format)
Grade 3 - English - Printable Worksheet  (PDF Format)Grade 3 - English - Printable Worksheet  (PDF Format)
Grade 3 - English - Printable Worksheet (PDF Format)
Sritoma Majumder
 
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptxSCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
Ronisha Das
 
spinal cord disorders (Myelopathies and radiculoapthies)
spinal cord disorders (Myelopathies and radiculoapthies)spinal cord disorders (Myelopathies and radiculoapthies)
spinal cord disorders (Myelopathies and radiculoapthies)
Mohamed Rizk Khodair
 
How to Configure Scheduled Actions in odoo 18
How to Configure Scheduled Actions in odoo 18How to Configure Scheduled Actions in odoo 18
How to Configure Scheduled Actions in odoo 18
Celine George
 
Drugs in Anaesthesia and Intensive Care,.pdf
Drugs in Anaesthesia and Intensive Care,.pdfDrugs in Anaesthesia and Intensive Care,.pdf
Drugs in Anaesthesia and Intensive Care,.pdf
crewot855
 
Tax evasion, Tax planning & Tax avoidance.pptx
Tax evasion, Tax  planning &  Tax avoidance.pptxTax evasion, Tax  planning &  Tax avoidance.pptx
Tax evasion, Tax planning & Tax avoidance.pptx
manishbaidya2017
 
BỘ ĐỀ TUYỂN SINH VÀO LỚP 10 TIẾNG ANH - 25 ĐỀ THI BÁM SÁT CẤU TRÚC MỚI NHẤT, ...
BỘ ĐỀ TUYỂN SINH VÀO LỚP 10 TIẾNG ANH - 25 ĐỀ THI BÁM SÁT CẤU TRÚC MỚI NHẤT, ...BỘ ĐỀ TUYỂN SINH VÀO LỚP 10 TIẾNG ANH - 25 ĐỀ THI BÁM SÁT CẤU TRÚC MỚI NHẤT, ...
BỘ ĐỀ TUYỂN SINH VÀO LỚP 10 TIẾNG ANH - 25 ĐỀ THI BÁM SÁT CẤU TRÚC MỚI NHẤT, ...
Nguyen Thanh Tu Collection
 
APGAR SCORE BY sweety Tamanna Mahapatra MSc Pediatric
APGAR SCORE  BY sweety Tamanna Mahapatra MSc PediatricAPGAR SCORE  BY sweety Tamanna Mahapatra MSc Pediatric
APGAR SCORE BY sweety Tamanna Mahapatra MSc Pediatric
SweetytamannaMohapat
 
Bridging the Transit Gap: Equity Drive Feeder Bus Design for Southeast Brooklyn
Bridging the Transit Gap: Equity Drive Feeder Bus Design for Southeast BrooklynBridging the Transit Gap: Equity Drive Feeder Bus Design for Southeast Brooklyn
Bridging the Transit Gap: Equity Drive Feeder Bus Design for Southeast Brooklyn
i4jd41bk
 
All About the 990 Unlocking Its Mysteries and Its Power.pdf
All About the 990 Unlocking Its Mysteries and Its Power.pdfAll About the 990 Unlocking Its Mysteries and Its Power.pdf
All About the 990 Unlocking Its Mysteries and Its Power.pdf
TechSoup
 
Ajanta Paintings: Study as a Source of History
Ajanta Paintings: Study as a Source of HistoryAjanta Paintings: Study as a Source of History
Ajanta Paintings: Study as a Source of History
Virag Sontakke
 
Drive Supporter Growth from Awareness to Advocacy with TechSoup Marketing Ser...
Drive Supporter Growth from Awareness to Advocacy with TechSoup Marketing Ser...Drive Supporter Growth from Awareness to Advocacy with TechSoup Marketing Ser...
Drive Supporter Growth from Awareness to Advocacy with TechSoup Marketing Ser...
TechSoup
 
CNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscessCNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscess
Mohamed Rizk Khodair
 
PHYSIOLOGY MCQS By DR. NASIR MUSTAFA (PHYSIOLOGY)
PHYSIOLOGY MCQS By DR. NASIR MUSTAFA (PHYSIOLOGY)PHYSIOLOGY MCQS By DR. NASIR MUSTAFA (PHYSIOLOGY)
PHYSIOLOGY MCQS By DR. NASIR MUSTAFA (PHYSIOLOGY)
Dr. Nasir Mustafa
 
dynastic art of the Pallava dynasty south India
dynastic art of the Pallava dynasty south Indiadynastic art of the Pallava dynasty south India
dynastic art of the Pallava dynasty south India
PrachiSontakke5
 
How to Manage Purchase Alternatives in Odoo 18
How to Manage Purchase Alternatives in Odoo 18How to Manage Purchase Alternatives in Odoo 18
How to Manage Purchase Alternatives in Odoo 18
Celine George
 
Cultivation Practice of Garlic in Nepal.pptx
Cultivation Practice of Garlic in Nepal.pptxCultivation Practice of Garlic in Nepal.pptx
Cultivation Practice of Garlic in Nepal.pptx
UmeshTimilsina1
 
Computer crime and Legal issues Computer crime and Legal issues
Computer crime and Legal issues Computer crime and Legal issuesComputer crime and Legal issues Computer crime and Legal issues
Computer crime and Legal issues Computer crime and Legal issues
Abhijit Bodhe
 
How to Configure Public Holidays & Mandatory Days in Odoo 18
How to Configure Public Holidays & Mandatory Days in Odoo 18How to Configure Public Holidays & Mandatory Days in Odoo 18
How to Configure Public Holidays & Mandatory Days in Odoo 18
Celine George
 
Grade 3 - English - Printable Worksheet (PDF Format)
Grade 3 - English - Printable Worksheet  (PDF Format)Grade 3 - English - Printable Worksheet  (PDF Format)
Grade 3 - English - Printable Worksheet (PDF Format)
Sritoma Majumder
 
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptxSCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
Ronisha Das
 
spinal cord disorders (Myelopathies and radiculoapthies)
spinal cord disorders (Myelopathies and radiculoapthies)spinal cord disorders (Myelopathies and radiculoapthies)
spinal cord disorders (Myelopathies and radiculoapthies)
Mohamed Rizk Khodair
 
How to Configure Scheduled Actions in odoo 18
How to Configure Scheduled Actions in odoo 18How to Configure Scheduled Actions in odoo 18
How to Configure Scheduled Actions in odoo 18
Celine George
 
Drugs in Anaesthesia and Intensive Care,.pdf
Drugs in Anaesthesia and Intensive Care,.pdfDrugs in Anaesthesia and Intensive Care,.pdf
Drugs in Anaesthesia and Intensive Care,.pdf
crewot855
 
Tax evasion, Tax planning & Tax avoidance.pptx
Tax evasion, Tax  planning &  Tax avoidance.pptxTax evasion, Tax  planning &  Tax avoidance.pptx
Tax evasion, Tax planning & Tax avoidance.pptx
manishbaidya2017
 
BỘ ĐỀ TUYỂN SINH VÀO LỚP 10 TIẾNG ANH - 25 ĐỀ THI BÁM SÁT CẤU TRÚC MỚI NHẤT, ...
BỘ ĐỀ TUYỂN SINH VÀO LỚP 10 TIẾNG ANH - 25 ĐỀ THI BÁM SÁT CẤU TRÚC MỚI NHẤT, ...BỘ ĐỀ TUYỂN SINH VÀO LỚP 10 TIẾNG ANH - 25 ĐỀ THI BÁM SÁT CẤU TRÚC MỚI NHẤT, ...
BỘ ĐỀ TUYỂN SINH VÀO LỚP 10 TIẾNG ANH - 25 ĐỀ THI BÁM SÁT CẤU TRÚC MỚI NHẤT, ...
Nguyen Thanh Tu Collection
 
APGAR SCORE BY sweety Tamanna Mahapatra MSc Pediatric
APGAR SCORE  BY sweety Tamanna Mahapatra MSc PediatricAPGAR SCORE  BY sweety Tamanna Mahapatra MSc Pediatric
APGAR SCORE BY sweety Tamanna Mahapatra MSc Pediatric
SweetytamannaMohapat
 
Bridging the Transit Gap: Equity Drive Feeder Bus Design for Southeast Brooklyn
Bridging the Transit Gap: Equity Drive Feeder Bus Design for Southeast BrooklynBridging the Transit Gap: Equity Drive Feeder Bus Design for Southeast Brooklyn
Bridging the Transit Gap: Equity Drive Feeder Bus Design for Southeast Brooklyn
i4jd41bk
 
All About the 990 Unlocking Its Mysteries and Its Power.pdf
All About the 990 Unlocking Its Mysteries and Its Power.pdfAll About the 990 Unlocking Its Mysteries and Its Power.pdf
All About the 990 Unlocking Its Mysteries and Its Power.pdf
TechSoup
 
Ajanta Paintings: Study as a Source of History
Ajanta Paintings: Study as a Source of HistoryAjanta Paintings: Study as a Source of History
Ajanta Paintings: Study as a Source of History
Virag Sontakke
 
Drive Supporter Growth from Awareness to Advocacy with TechSoup Marketing Ser...
Drive Supporter Growth from Awareness to Advocacy with TechSoup Marketing Ser...Drive Supporter Growth from Awareness to Advocacy with TechSoup Marketing Ser...
Drive Supporter Growth from Awareness to Advocacy with TechSoup Marketing Ser...
TechSoup
 

Java script

  • 2. WHAT IS JAVASCRIPT? • JavaScript is a scripting language (a scripting language is a lightweight programming language) • JavaScript was designed to add interactivity to HTML pages • JavaScript is an interpreted language (means that scripts execute without preliminary compilation) • Everyone can use JavaScript without purchasing a license • JavaScript is used in millions of Web pages to improve the design, validate forms, detect browsers, create cookies, and much more. • JavaScript works in all major browsers, such as Internet Explorer, Mozilla, Firefox, Opera.
  • 3. Where did it come from • Originally called LiveScript at Netscape started out to be a server side scripting language for providing database connectivity and dynamic HTML generation on Netscape Web Servers. • Netscape decided it would be a good thing for their browsers and servers to speak the same language so it got included in Navigator. • Netscape in alliance with Sun jointly announced the language and its new name Java Script • Because of rapid acceptance by the web community Microsoft forced to include in IE Browser
  • 4. Are Java and JavaScript the Same? NO! Java and JavaScript are two completely different languages in both concept and design! • Java (developed by Sun • JavaScript (developed by Microsystems) is a powerful and Netscape), is a smaller language much more complex that does not create applets or programming language - in the standalone applications. In its same category as C and C++. most common form • It can be used to create today, JavaScript resides inside standalone applications and a HTML documents, and can special type of mini provide levels of interactivity far application, called an applet. beyond typically flat HTML pages
  • 5. How to Put a JavaScript Into an HTML Page? We can add JavaScript in three ways in our document: 1) Inline <input type="button" id="hello-world2" value="Hello" onClick="alert('Hello World!');" /> 2) Embedded <script type="text/javascript"> function helloWorld() { alert('Hello World!') ; } </script> 3) External <head> <script type="text/javascript" language="javascript" src="hello.js"></script></head>
  • 6. How to Put a JavaScript Into an HTML Page? Ending Statements With a Semicolon? <html> • With traditional programming <body> languages, like C++ and Java, each code <script type="text/javascript"> statement has to end with a semicolon document.write("Hello World!"); (;). </script> • Many programmers continue this habit </body> when writing JavaScript, but in </html> general, semicolons are optional! However, semicolons are required if you want to put more than one statement on a single line. NOTE: At times JavaScript is disabled in some browsers and it becomes difficult to get appropriate behavior and the user get confused, so to avoid such conditions we should check if it is enable or we should display an appropriate message. We can do this with the help of: <noscript> <p>This will not be displayed if JavaScript is enabled</p> </noscript>
  • 7. JavaScript Terminology Objects: Properties: • Almost everything in JavaScript • Properties are object attributes. is an Object: String, Number, • Object properties are defined by Array, Function.... using the object's name, a • An object is just a special kind of period, and the property name. data, with properties and • e.g., background color is methods. expressed by: • Objects have properties that act document.bgcolor as modifiers. document is the object .bgcolor is the property. Eg: personObj=new Object(); personObj.firstname="John"; personObj.lastname="Doe"; personObj.age=50; personObj.eyecolor="blue";
  • 8. JavaScript Terminology Methods: Events: • Methods are actions applied to • Events associate an object with particular objects. Methods are an action. what objects can do. e.g., the onclick event handler e.g., action can change an image. document.write(”Hello e.g., the onSubmit event handler World") sends a form. document is the object. • User actions trigger events. write is the method.
  • 9. JavaScript Terminology Functions: Values: • Functions are named statements • Values are bits of information. that performs tasks. • Values, types and some examples e.g. function doWhatever() include: { Number: 1, 2, 3, etc. statement here String: characters enclosed in quotes. } Boolean: true or false. The curly braces contain the Object: image, form statements of the function. Function: validate, doWhatever • JavaScript has built-in functions, and we can write our own.
  • 10. JavaScript Terminology Variables: Expressions : • Variables contain values and use • Expressions are commands that the equal sign to specify their assign values to variables. value. • Expressions always use an • Variables are created by assignment operator, such as declaration using the var the equals sign. command with or without an e.g., var month = May; is an initial value state. expression. e.g. var month; • Expressions end with a e.g. var month = April; semicolon.
  • 11. JavaScript Terminology Operators: • Operators are used to handle variables. Types of operators with examples: Arithmetic operators, such as plus(+). Comparisons operators, such as equals(==). Logical operators, such as AND. Assignment like (=). + Operator: The + operator can also be used to add string variables or text values together.
  • 12. Condition statements • Very often when we write code, we want to perform different actions for different decisions. we can use conditional statements in our code to do this. In JavaScript we have the following conditional statements: • if statement - use this statement if we want to execute some code only if a specified condition is true • if...else statement - use this statement if we want to execute some code if the condition is true and another code if the condition is false • if...else if....else statement - use this statement if we want to select one of many blocks of code to be executed • switch statement - use this statement if we want to select one of many blocks of code to be executed
  • 13. Loops JavaScript performs several types of repetitive operations, called "looping". • for loop: The for loop is executed till a specified condition returns false for (initialization; condition; increment) { // statements } • while loop: The while statement repeats a loop as long as a specified condition evaluates to true. while (condition) { // statements }
  • 14. Arrays Arrays are usually a group of the same variable type that use an index number to distinguish them from each other. Arrays are one way of keeping a program more organized. Creating arrays: Initializing an array: • var badArray = new Array(10); • Var myArray= new Array(“January”,” February”,” // Creates an empty Array that's sized March”); for 10 elements. • var myArray = ['January', 'February', 'March']; • var goodArray= [10]; document.write(myArray[0]);//output: January //Creates an Array with 10 as the first document.write(myArray[1]);//output: February element. document.write(myArray[2]);//output: March
  • 15. JavaScript Popup Boxes It is possible to make three different kinds of popup boxes: 1) Alert Box • An alert box is often used if we want to make sure information comes through to the user. • When an alert box pops up, the user will have to click "OK" to proceed. <script> alert("Hello World") </script>
  • 16. 2) Confirm Box • A confirm box is often used if we want the user to verify or accept something. • When a confirm box pops up, the user will have to click either "OK" or "Cancel" to proceed. • If the user clicks "OK", the box returns true. If the user clicks "Cancel", the box returns false. <script> var r=confirm("Press a button!"); if (r==true) document.write("You pressed OK!“); else document.write("You pressed Cancel!“); </script>
  • 17. 3) Prompt Box • A prompt box is often used if you want the user to input a value before entering a page. • When a prompt box pops up, the user will have to click either "OK" or "Cancel" to proceed after entering an input value. • If the user clicks "OK“, the box returns the input value. If the user clicks "Cancel“, the box returns null. <script> x=prompt (“Please enter your name”, “sahil goel ”) document.write(“Welcome <br>”+x) </script>
  • 18. DOM • The Document Object Model (DOM) is the model that describes how all elements in an HTML page, like input fields, images, paragraphs etc., are related to the topmost structure: the document itself. By calling the element by its proper DOM name, we can influence it. • In DOM each object, whatever it may be exactly, is a Node. Node object: We can traverse through different nodes with the help of certain node properties and methods: Eg: firstChild, lastChild, parentNode, nextSibling, previousSibling etc. Document object:The Document object gives us access to the document's data. Some document methods are: Eg: getElementById(), getElementsByTagName() etc.
  • 19. What is a Cookie? A cookie is a small text file that JavaScript can use to store information about a user. • There are two types of cookies: – 1) Session Cookies – 2) Persistent Cookies Session Cookies :A browser stores session cookies in memory. • Once a browser session ends, browser loses the contents of a session cookie. –Persistent Cookies: Browsers store persistent cookies to a user’s hard drive. • We can use persistent cookies to get information about a user that we can use when the user returns to a website at a later date.
  • 20. More about Cookies • JavaScript deals with cookies as objects. • JavaScript works with cookies using the document.cookie attribute. Examples of cookie usage: • User preferences • Saving form data • Tracking online shopping habits
  • 21. Parts of a Cookie Object • name – An identifier by which we reference a particular cookie. • value – The information we wish to save, in reference to a particular cookie. • expires – A GMT-formatted date specifying the date (in milliseconds) when a cookie will expire. • path – Specifies the path of the web server in which the cookie is valid. By default, set to the path of the page that set the cookie. However, commonly specified to /, the root directory. • domain – Specifies the domain for which the cookie is valid. Set, by default, only to the full domain of a page.. • secure – Specifies that a web browser needs a secure HTTP connection to access a cookie.
  • 22. Setting a Cookie – General Form: document.cookie = “cookieName = cookieValue; expires = expireDate; path = pathName; domain = domainName; secure”; Escape Sequences: • When we set cookie values, we must first convert the string values that set a cookie so that the string doesn’t contain white space, commas or semi-colons. • We can use JavaScript’s intrinsic escape() function to convert white space and punctuation with escape sequences. • Conversely, we can use unescape() to view text encoded with escape().
  • 23. Cookie limitations: • A given domain may only set 20 cookies per machine. • A single browser may only store 300 cookies. • Browsers limit a single cookie to 4KB.