SlideShare a Scribd company logo
WWW.IPRISMTECH.COM
www.iprismtech.com

 JavaScript ("JS" for short) is a full-fledged dynamic programming language that, when
applied to an HTML document, can provide dynamic interactivity on websites. It was
invented by Brendan Eich, co-founder of the Mozilla project, the Mozilla Foundation,
and the Mozilla Corporation.
 JavaScript is incredibly versatile. You can start small, with carousels, image galleries,
fluctuating layouts, and responses to button clicks. With more experience you'll be
able to create games, animated 2D and 3D graphics, comprehensive database-driven
apps, and much more!
What is JavaScript, really?
www.iprismtech.com
 JavaScript itself is fairly compact yet very flexible. Developers have
written a large variety of tools complementing the core JavaScript
language, unlocking a vast amount of extra functionality with minimum
effort. These include:
 Application Programming Interfaces (APIs) built into web browsers,
providing functionality like dynamically creating HTML and setting CSS
styles, collecting and manipulating a video stream from the user's
webcam, or generating 3D graphics and audio samples.
 Third-party APIs to allow developers to incorporate functionality in their
sites from other content providers, such as Twitter or Facebook.
 Third-party frameworks and libraries you can apply to your HTML to
allow you to rapidly build up sites and applications.
www.iprismtech.com

 First, go to your test site and create a new file called main.js. Save it in
your scripts folder.
 Next, in your index.html file enter the following element on a new line
just before the closing </body> tag:<script
src="scripts/main.js"></script>
 This is basically doing the same job as the <link> element for CSS — it
applies the JavaScript to the page, so it can have an effect on the HTML
(along with the CSS, and anything else on the page).
 Now add the following code to the main.js file:var myHeading =
document.querySelector('h1'); myHeading.textContent = 'Hello world!';
 Finally, make sure the HTML and JavaScript files are saved, and
load index.html in the browser.
A "hello world" example
www.iprismtech.com

 Your heading text has now been changed to "Hello world!" using JavaScript.
You did this by first using a function called querySelector() to grab a
reference to your heading, and store it in a variable called myHeading. This
is very similar to what we did using CSS selectors. When wanting to do
something to an element, you first need to select it.
 After that, you set the value of
the myHeading variable's textContent property (which represents the
content of the heading) to "Hello world!".
What happened?
www.iprismtech.com

 Let's explain some of the basic features of the JavaScript language, to give
you greater understanding of how it all works. Better yet, these features are
common to all programming languages. If you master these fundamentals,
you're on your way to being able to programme just about anything!
Language basics crash course
www.iprismtech.com
 Variables are containers that you can store values in. You start by declaring a
variable with the var keyword, followed by any name you want to call it:
 var myVariable;Note: All statements in JavaScript must end with a semi-colon, to
indicate that this is where the statement ends. If you don't include these, you can
get unexpected results.
 Note: You can name a variable nearly anything, but there are some name
restrictions (see this article on variable naming rules.) If you are unsure, you
can check your variable name to see if it is valid.
 Note: JavaScript is case sensitive — myVariable is a different variable
to myvariable. If you are getting problems in your code, check the casing!
 After declaring a variable, you can give it a value:
 myVariable = 'Bob';You can do both these operations on the same line if you wish:
 var myVariable = 'Bob';You can retrieve the value by just calling the variable by
name:
 myVariable;After giving a variable a value, you can later choose to change it:
 var myVariable = 'Bob'; myVariable = 'Steve';
Variables
www.iprismtech.com
Variable Explanation Example
String
A sequence of text
known as a string. To
signify that the
variable is a string,
you should enclose it
in quote marks.
var myVariable =
'Bob';
Number
A number. Numbers
don't have quotes
around them.
var myVariable = 10;
Boolean
A True/False value.
The
words trueand false ar
e special keywords in
JS, and don't need
quotes.
var myVariable = true;
Array
A structure that allows
you to store multiple
values in one single
reference.
var myVariable =
[1,'Bob','Steve',10];
Refer to each member
of the array like this:
myVariable[0], myVari
able[1], etc.
Object
Basically, anything.
Everything in
JavaScript is an object,
and can be stored in a
variable. Keep this in
mind as you learn.
var myVariable =
document.querySelect
or('h1');
All of the above
examples too.
DATA TYPES
www.iprismtech.com

 You can put comments into JavaScript code, just as you can in CSS:
 /* Everything in between is a comment. */If your comment contains no line
breaks, it's often easier to put it behind two slashes like this:
 // This is a comment
Comments
www.iprismtech.com

 An operator is a mathematical symbol which produces a result based on two
values (or variables). In the following table you can see some of the simplest
operators, along with some examples to try out in the JavaScript console.
Operators
Operator Explanation Symbol(s) Example
add/concatenati
on
Used to add two
numbers
together, or glue
two strings
together.
+
6 + 9;
"Hello " +
"world!";
subtract,
multiply, divide
These do what
you'd expect
them to do in
basic math.
-, *, /
9 - 3;
8 * 2; // multiply
in JS is an asterisk
9 / 3;
assignment
operator
You've seen this
already: it assigns
a value to a
variable.
=
var myVariable =
'Bob';
www.iprismtech.com

 Identity operator Does a test to see if two values are equal to one
another, and returns a true/false (Boolean) result. === var
myVariable = 3;
 myVariable === 4;
 Negation, not equal Returns the logically opposite value of what it
precedes; it turns a true into a false, etc. When it is used alongside the
Equality operator, the negation operator tests whether two values are not
equal. !, !==
 The basic expression is true, but the comparison returns false because we've
negated it:
 var myVariable = 3;
 !(myVariable === 3);
 Here we are testing "is myVariable NOT equal to 3". This returns false
because myVariable IS equal to 3.
 var myVariable = 3;
 myVariable !== 3;
www.iprismtech.com

 Conditionals are code structures which allow you to test if an expression
returns true or not, running alternative code revealed by its result. The
most common form of conditional is called if ... else. So for example:
 var iceCream = 'chocolate'; if (iceCream === 'chocolate') { alert('Yay, I
love chocolate ice cream!'); } else { alert('Awwww, but chocolate is my
favorite...'); }The expression inside the if ( ... ) is the test — this uses the
identity operator (as described above) to compare the
variable iceCream with the string chocolate to see if the two are equal. If
this comparison returns true, the first block of code is run. If the
comparison is not true, the first block is skipped and the second code
block, after the elsestatement, is run instead.
Conditionals
www.iprismtech.com
 Functions are a way of packaging functionality that you wish to reuse. When
you need the procedure you can call a function, with the function name,
instead of rewriting the entire code each time. You have already seen some
uses of functions above, for example:
 var myVariable = document.querySelector('h1');
 alert('hello!');
 These functions, document.querySelector and alert, are built into the
browser for you to use whenever you desire.
 If you see something which looks like a variable name, but has brackets —
() — after it, it is likely a function. Functions often take arguments — bits of
data they need to do their job. These go inside the brackets, separated by
commas if there is more than one argument.
 For example, the alert() function makes a pop-up box appear inside the
browser window, but we need to give it a string as an argument to tell the
function what to write in the pop-up box.
Functions
www.iprismtech.com

 The good news is you can define your own functions — in this next example
we write a simple function which takes two numbers as arguments and
multiplies them:
 function multiply(num1,num2) { var result = num1 * num2; return result;
}Try running the above function in the console, then test with several
arguments. For example:
 multiply(4,7); multiply(20,20); multiply(0.5,3);
www.iprismtech.com
 Real interactivity on a website needs events. These are code structures which
listen for things happening in browser, running code in response. The most
obvious example is the click event, which is fired by the browser when you
click on something with your mouse. To demonstrate this, enter the
following into your console, then click on the current webpage:
 document.querySelector('html').onclick = function() { alert('Ouch! Stop
poking me!'); }There are many ways to attach an event to an element.
Here we select the HTML element, setting its onclick handler property equal
to an anonymous (i.e. nameless) function, which contains the code we want
the click event to run.
 Note that
 document.querySelector('html').onclick = function() {};is equivalent to
 var myHTML = document.querySelector('html'); myHTML.onclick =
function() {};
 It's just shorter.
Events
www.iprismtech.com

 iPrism Technologies
 Contact-+918885617929
 Email-id: sales@iprismtech.com
Thank you
www.iprismtech.com

More Related Content

What's hot (20)

ZIP
Fundamental JavaScript [In Control 2009]
Aaron Gustafson
 
DOCX
Java script basics
Thakur Amit Tomer
 
PDF
Secrets of JavaScript Libraries
jeresig
 
PPT
Learn javascript easy steps
prince Loffar
 
PDF
JavaScript Best Pratices
ChengHui Weng
 
PPTX
Lab #2: Introduction to Javascript
Walid Ashraf
 
PDF
Design patterns in java script, jquery, angularjs
Ravi Bhadauria
 
PDF
Basics of JavaScript
Bala Narayanan
 
PDF
Javascript Best Practices
Christian Heilmann
 
PPTX
JavaScript Fundamentals & JQuery
Jamshid Hashimi
 
PPTX
1. java script language fundamentals
Rajiv Gupta
 
PDF
Patterns for JVM languages - Geecon 2014
Jaroslaw Palka
 
PPT
Javascript
mussawir20
 
PPT
JavaScript Tutorial
Bui Kiet
 
PPT
JavaScript Workshop
Pamela Fox
 
PPS
Advisor Jumpstart: JavaScript
dominion
 
PPTX
Angular Mini-Challenges
Jose Mendez
 
PPTX
Java script
Jay Patel
 
PDF
МИХАЙЛО БОДНАРЧУК «SuperCharged End to End Testing with CodeceptJS» QADay 2019
QADay
 
PDF
JavaScript: DOM and jQuery
維佋 唐
 
Fundamental JavaScript [In Control 2009]
Aaron Gustafson
 
Java script basics
Thakur Amit Tomer
 
Secrets of JavaScript Libraries
jeresig
 
Learn javascript easy steps
prince Loffar
 
JavaScript Best Pratices
ChengHui Weng
 
Lab #2: Introduction to Javascript
Walid Ashraf
 
Design patterns in java script, jquery, angularjs
Ravi Bhadauria
 
Basics of JavaScript
Bala Narayanan
 
Javascript Best Practices
Christian Heilmann
 
JavaScript Fundamentals & JQuery
Jamshid Hashimi
 
1. java script language fundamentals
Rajiv Gupta
 
Patterns for JVM languages - Geecon 2014
Jaroslaw Palka
 
Javascript
mussawir20
 
JavaScript Tutorial
Bui Kiet
 
JavaScript Workshop
Pamela Fox
 
Advisor Jumpstart: JavaScript
dominion
 
Angular Mini-Challenges
Jose Mendez
 
Java script
Jay Patel
 
МИХАЙЛО БОДНАРЧУК «SuperCharged End to End Testing with CodeceptJS» QADay 2019
QADay
 
JavaScript: DOM and jQuery
維佋 唐
 

Viewers also liked (13)

DOCX
YASH.DOCX
Yashwanth Kumar CL
 
PPTX
Usaha kecil menengah( ukm ) erlina risnandari 11140131 ( 12 )
erlina risnandari
 
PDF
Evaluación diagnóstica por escuela
María del Carmen de Leon Martirena
 
DOCX
Cuestionario Bransford
Dianita Cuamatzi
 
PDF
Photobook
John Siew
 
DOCX
Historia a través de ideas
humanismo
 
PPTX
Proyecto sena blog blogger blogspot
abacevedo
 
PPT
Kamil Presentation final
Kamil Sardar
 
PDF
Programa electoral PABA 2011
Antonio Gálvez
 
PPTX
Guia instalacion gretl
luisperdices
 
PDF
外贸企业网站的定位和呈现(外贸企业定位)
Lawrence Sun
 
PDF
Formación en didáctica tic. educación infantil
Marisol Tejada Ruiz
 
PPTX
Bidang Garapan Personalia
Fitria Kusuma Wati
 
Usaha kecil menengah( ukm ) erlina risnandari 11140131 ( 12 )
erlina risnandari
 
Evaluación diagnóstica por escuela
María del Carmen de Leon Martirena
 
Cuestionario Bransford
Dianita Cuamatzi
 
Photobook
John Siew
 
Historia a través de ideas
humanismo
 
Proyecto sena blog blogger blogspot
abacevedo
 
Kamil Presentation final
Kamil Sardar
 
Programa electoral PABA 2011
Antonio Gálvez
 
Guia instalacion gretl
luisperdices
 
外贸企业网站的定位和呈现(外贸企业定位)
Lawrence Sun
 
Formación en didáctica tic. educación infantil
Marisol Tejada Ruiz
 
Bidang Garapan Personalia
Fitria Kusuma Wati
 
Ad

Similar to Java script basics (20)

PPTX
Javascript note for engineering notes.pptx
engineeradda55
 
PPTX
gdscWorkShopJavascriptintroductions.pptx
sandeshshahapur
 
PPTX
FFW Gabrovo PMG - JavaScript 1
Toni Kolev
 
PDF
Iwt note(module 2)
SANTOSH RATH
 
PDF
Lecture 10.pdf
ssuser0890d1
 
PPTX
Web designing unit 4
Dr. SURBHI SAROHA
 
PPT
UNIT 3.ppt
MadhurRajVerma1
 
PPTX
Java script ppt from students in internet technology
SherinRappai
 
PDF
internet Chapter 4-JavascripPrepare a ppt of video compression techniques bas...
wabii3179com
 
PPTX
Java script
bosybosy
 
DOCX
Unit 2.4
Abhishek Kesharwani
 
PDF
JavaScript_introduction_upload.pdf
Kongu Engineering College, Perundurai, Erode
 
PPTX
unit4 wp.pptxjvlbpuvghuigv8ytg2ugvugvuygv
utsavsd11
 
PDF
8.-Javascript-report powerpoint presentation
JohnLagman3
 
PPT
Js mod1
VARSHAKUMARI49
 
PPTX
Journey To The Front End World - Part3 - The Machine
Irfan Maulana
 
PPTX
IntroJavascript.pptx cjfjgjggkgutufjf7fjvit8t
SooryaPrashanth1
 
PPTX
JavaScript lesson 1.pptx
MuqaddarNiazi1
 
PDF
Client sidescripting javascript
Selvin Josy Bai Somu
 
PPT
JavaScript - An Introduction
Manvendra Singh
 
Javascript note for engineering notes.pptx
engineeradda55
 
gdscWorkShopJavascriptintroductions.pptx
sandeshshahapur
 
FFW Gabrovo PMG - JavaScript 1
Toni Kolev
 
Iwt note(module 2)
SANTOSH RATH
 
Lecture 10.pdf
ssuser0890d1
 
Web designing unit 4
Dr. SURBHI SAROHA
 
UNIT 3.ppt
MadhurRajVerma1
 
Java script ppt from students in internet technology
SherinRappai
 
internet Chapter 4-JavascripPrepare a ppt of video compression techniques bas...
wabii3179com
 
Java script
bosybosy
 
JavaScript_introduction_upload.pdf
Kongu Engineering College, Perundurai, Erode
 
unit4 wp.pptxjvlbpuvghuigv8ytg2ugvugvuygv
utsavsd11
 
8.-Javascript-report powerpoint presentation
JohnLagman3
 
Journey To The Front End World - Part3 - The Machine
Irfan Maulana
 
IntroJavascript.pptx cjfjgjggkgutufjf7fjvit8t
SooryaPrashanth1
 
JavaScript lesson 1.pptx
MuqaddarNiazi1
 
Client sidescripting javascript
Selvin Josy Bai Somu
 
JavaScript - An Introduction
Manvendra Singh
 
Ad

Recently uploaded (20)

PPTX
MuleSoft MCP Support (Model Context Protocol) and Use Case Demo
shyamraj55
 
PPTX
Practical Applications of AI in Local Government
OnBoard
 
PPTX
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
 
PDF
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
PDF
FME in Overdrive: Unleashing the Power of Parallel Processing
Safe Software
 
PPTX
MARTSIA: A Tool for Confidential Data Exchange via Public Blockchain - Pitch ...
Michele Kryston
 
PPTX
Enabling the Digital Artisan – keynote at ICOCI 2025
Alan Dix
 
PDF
Understanding The True Cost of DynamoDB Webinar
ScyllaDB
 
PDF
GDG Cloud Southlake #44: Eyal Bukchin: Tightening the Kubernetes Feedback Loo...
James Anderson
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PDF
DoS Attack vs DDoS Attack_ The Silent Wars of the Internet.pdf
CyberPro Magazine
 
PPTX
Wondershare Filmora Crack Free Download 2025
josanj305
 
PPTX
2025 HackRedCon Cyber Career Paths.pptx Scott Stanton
Scott Stanton
 
PPTX
Securing Model Context Protocol with Keycloak: AuthN/AuthZ for MCP Servers
Hitachi, Ltd. OSS Solution Center.
 
PPTX
01_Approach Cyber- DORA Incident Management.pptx
FinTech Belgium
 
PPTX
Paycifi - Programmable Trust_Breakfast_PPTXT
FinTech Belgium
 
PDF
Quantum Threats Are Closer Than You Think – Act Now to Stay Secure
WSO2
 
PDF
ICONIQ State of AI Report 2025 - The Builder's Playbook
Razin Mustafiz
 
PPTX
Agentforce World Tour Toronto '25 - MCP with MuleSoft
Alexandra N. Martinez
 
PDF
Hello I'm "AI" Your New _________________
Dr. Tathagat Varma
 
MuleSoft MCP Support (Model Context Protocol) and Use Case Demo
shyamraj55
 
Practical Applications of AI in Local Government
OnBoard
 
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
 
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
FME in Overdrive: Unleashing the Power of Parallel Processing
Safe Software
 
MARTSIA: A Tool for Confidential Data Exchange via Public Blockchain - Pitch ...
Michele Kryston
 
Enabling the Digital Artisan – keynote at ICOCI 2025
Alan Dix
 
Understanding The True Cost of DynamoDB Webinar
ScyllaDB
 
GDG Cloud Southlake #44: Eyal Bukchin: Tightening the Kubernetes Feedback Loo...
James Anderson
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
DoS Attack vs DDoS Attack_ The Silent Wars of the Internet.pdf
CyberPro Magazine
 
Wondershare Filmora Crack Free Download 2025
josanj305
 
2025 HackRedCon Cyber Career Paths.pptx Scott Stanton
Scott Stanton
 
Securing Model Context Protocol with Keycloak: AuthN/AuthZ for MCP Servers
Hitachi, Ltd. OSS Solution Center.
 
01_Approach Cyber- DORA Incident Management.pptx
FinTech Belgium
 
Paycifi - Programmable Trust_Breakfast_PPTXT
FinTech Belgium
 
Quantum Threats Are Closer Than You Think – Act Now to Stay Secure
WSO2
 
ICONIQ State of AI Report 2025 - The Builder's Playbook
Razin Mustafiz
 
Agentforce World Tour Toronto '25 - MCP with MuleSoft
Alexandra N. Martinez
 
Hello I'm "AI" Your New _________________
Dr. Tathagat Varma
 

Java script basics

  • 2.   JavaScript ("JS" for short) is a full-fledged dynamic programming language that, when applied to an HTML document, can provide dynamic interactivity on websites. It was invented by Brendan Eich, co-founder of the Mozilla project, the Mozilla Foundation, and the Mozilla Corporation.  JavaScript is incredibly versatile. You can start small, with carousels, image galleries, fluctuating layouts, and responses to button clicks. With more experience you'll be able to create games, animated 2D and 3D graphics, comprehensive database-driven apps, and much more! What is JavaScript, really? www.iprismtech.com
  • 3.  JavaScript itself is fairly compact yet very flexible. Developers have written a large variety of tools complementing the core JavaScript language, unlocking a vast amount of extra functionality with minimum effort. These include:  Application Programming Interfaces (APIs) built into web browsers, providing functionality like dynamically creating HTML and setting CSS styles, collecting and manipulating a video stream from the user's webcam, or generating 3D graphics and audio samples.  Third-party APIs to allow developers to incorporate functionality in their sites from other content providers, such as Twitter or Facebook.  Third-party frameworks and libraries you can apply to your HTML to allow you to rapidly build up sites and applications. www.iprismtech.com
  • 4.   First, go to your test site and create a new file called main.js. Save it in your scripts folder.  Next, in your index.html file enter the following element on a new line just before the closing </body> tag:<script src="scripts/main.js"></script>  This is basically doing the same job as the <link> element for CSS — it applies the JavaScript to the page, so it can have an effect on the HTML (along with the CSS, and anything else on the page).  Now add the following code to the main.js file:var myHeading = document.querySelector('h1'); myHeading.textContent = 'Hello world!';  Finally, make sure the HTML and JavaScript files are saved, and load index.html in the browser. A "hello world" example www.iprismtech.com
  • 5.   Your heading text has now been changed to "Hello world!" using JavaScript. You did this by first using a function called querySelector() to grab a reference to your heading, and store it in a variable called myHeading. This is very similar to what we did using CSS selectors. When wanting to do something to an element, you first need to select it.  After that, you set the value of the myHeading variable's textContent property (which represents the content of the heading) to "Hello world!". What happened? www.iprismtech.com
  • 6.   Let's explain some of the basic features of the JavaScript language, to give you greater understanding of how it all works. Better yet, these features are common to all programming languages. If you master these fundamentals, you're on your way to being able to programme just about anything! Language basics crash course www.iprismtech.com
  • 7.  Variables are containers that you can store values in. You start by declaring a variable with the var keyword, followed by any name you want to call it:  var myVariable;Note: All statements in JavaScript must end with a semi-colon, to indicate that this is where the statement ends. If you don't include these, you can get unexpected results.  Note: You can name a variable nearly anything, but there are some name restrictions (see this article on variable naming rules.) If you are unsure, you can check your variable name to see if it is valid.  Note: JavaScript is case sensitive — myVariable is a different variable to myvariable. If you are getting problems in your code, check the casing!  After declaring a variable, you can give it a value:  myVariable = 'Bob';You can do both these operations on the same line if you wish:  var myVariable = 'Bob';You can retrieve the value by just calling the variable by name:  myVariable;After giving a variable a value, you can later choose to change it:  var myVariable = 'Bob'; myVariable = 'Steve'; Variables www.iprismtech.com
  • 8. Variable Explanation Example String A sequence of text known as a string. To signify that the variable is a string, you should enclose it in quote marks. var myVariable = 'Bob'; Number A number. Numbers don't have quotes around them. var myVariable = 10; Boolean A True/False value. The words trueand false ar e special keywords in JS, and don't need quotes. var myVariable = true; Array A structure that allows you to store multiple values in one single reference. var myVariable = [1,'Bob','Steve',10]; Refer to each member of the array like this: myVariable[0], myVari able[1], etc. Object Basically, anything. Everything in JavaScript is an object, and can be stored in a variable. Keep this in mind as you learn. var myVariable = document.querySelect or('h1'); All of the above examples too. DATA TYPES www.iprismtech.com
  • 9.   You can put comments into JavaScript code, just as you can in CSS:  /* Everything in between is a comment. */If your comment contains no line breaks, it's often easier to put it behind two slashes like this:  // This is a comment Comments www.iprismtech.com
  • 10.   An operator is a mathematical symbol which produces a result based on two values (or variables). In the following table you can see some of the simplest operators, along with some examples to try out in the JavaScript console. Operators Operator Explanation Symbol(s) Example add/concatenati on Used to add two numbers together, or glue two strings together. + 6 + 9; "Hello " + "world!"; subtract, multiply, divide These do what you'd expect them to do in basic math. -, *, / 9 - 3; 8 * 2; // multiply in JS is an asterisk 9 / 3; assignment operator You've seen this already: it assigns a value to a variable. = var myVariable = 'Bob'; www.iprismtech.com
  • 11.   Identity operator Does a test to see if two values are equal to one another, and returns a true/false (Boolean) result. === var myVariable = 3;  myVariable === 4;  Negation, not equal Returns the logically opposite value of what it precedes; it turns a true into a false, etc. When it is used alongside the Equality operator, the negation operator tests whether two values are not equal. !, !==  The basic expression is true, but the comparison returns false because we've negated it:  var myVariable = 3;  !(myVariable === 3);  Here we are testing "is myVariable NOT equal to 3". This returns false because myVariable IS equal to 3.  var myVariable = 3;  myVariable !== 3; www.iprismtech.com
  • 12.   Conditionals are code structures which allow you to test if an expression returns true or not, running alternative code revealed by its result. The most common form of conditional is called if ... else. So for example:  var iceCream = 'chocolate'; if (iceCream === 'chocolate') { alert('Yay, I love chocolate ice cream!'); } else { alert('Awwww, but chocolate is my favorite...'); }The expression inside the if ( ... ) is the test — this uses the identity operator (as described above) to compare the variable iceCream with the string chocolate to see if the two are equal. If this comparison returns true, the first block of code is run. If the comparison is not true, the first block is skipped and the second code block, after the elsestatement, is run instead. Conditionals www.iprismtech.com
  • 13.  Functions are a way of packaging functionality that you wish to reuse. When you need the procedure you can call a function, with the function name, instead of rewriting the entire code each time. You have already seen some uses of functions above, for example:  var myVariable = document.querySelector('h1');  alert('hello!');  These functions, document.querySelector and alert, are built into the browser for you to use whenever you desire.  If you see something which looks like a variable name, but has brackets — () — after it, it is likely a function. Functions often take arguments — bits of data they need to do their job. These go inside the brackets, separated by commas if there is more than one argument.  For example, the alert() function makes a pop-up box appear inside the browser window, but we need to give it a string as an argument to tell the function what to write in the pop-up box. Functions www.iprismtech.com
  • 14.   The good news is you can define your own functions — in this next example we write a simple function which takes two numbers as arguments and multiplies them:  function multiply(num1,num2) { var result = num1 * num2; return result; }Try running the above function in the console, then test with several arguments. For example:  multiply(4,7); multiply(20,20); multiply(0.5,3); www.iprismtech.com
  • 15.  Real interactivity on a website needs events. These are code structures which listen for things happening in browser, running code in response. The most obvious example is the click event, which is fired by the browser when you click on something with your mouse. To demonstrate this, enter the following into your console, then click on the current webpage:  document.querySelector('html').onclick = function() { alert('Ouch! Stop poking me!'); }There are many ways to attach an event to an element. Here we select the HTML element, setting its onclick handler property equal to an anonymous (i.e. nameless) function, which contains the code we want the click event to run.  Note that  document.querySelector('html').onclick = function() {};is equivalent to  var myHTML = document.querySelector('html'); myHTML.onclick = function() {};  It's just shorter. Events www.iprismtech.com
  • 16.   iPrism Technologies  Contact-+918885617929  Email-id: [email protected] Thank you www.iprismtech.com