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

PDF
Basic JavaScript Tutorial
PDF
Javascript basics
PPTX
Introduction to JavaScript Basics.
PDF
MVC Design Pattern in JavaScript by ADMEC Multimedia Institute
PPT
PPTX
Javascript best practices
PPTX
Java script
PPTX
Lab#1 - Front End Development
Basic JavaScript Tutorial
Javascript basics
Introduction to JavaScript Basics.
MVC Design Pattern in JavaScript by ADMEC Multimedia Institute
Javascript best practices
Java script
Lab#1 - Front End Development

What's hot (20)

ZIP
Fundamental JavaScript [In Control 2009]
DOCX
Java script basics
PDF
Secrets of JavaScript Libraries
PPT
Learn javascript easy steps
PDF
JavaScript Best Pratices
PPTX
Lab #2: Introduction to Javascript
PDF
Design patterns in java script, jquery, angularjs
PDF
Basics of JavaScript
PDF
Javascript Best Practices
PPTX
JavaScript Fundamentals & JQuery
PPTX
1. java script language fundamentals
PDF
Patterns for JVM languages - Geecon 2014
PPT
Javascript
PPT
JavaScript Tutorial
PPT
JavaScript Workshop
PPS
Advisor Jumpstart: JavaScript
PPTX
Angular Mini-Challenges
PPTX
Java script
PDF
МИХАЙЛО БОДНАРЧУК «SuperCharged End to End Testing with CodeceptJS» QADay 2019
PDF
JavaScript: DOM and jQuery
Fundamental JavaScript [In Control 2009]
Java script basics
Secrets of JavaScript Libraries
Learn javascript easy steps
JavaScript Best Pratices
Lab #2: Introduction to Javascript
Design patterns in java script, jquery, angularjs
Basics of JavaScript
Javascript Best Practices
JavaScript Fundamentals & JQuery
1. java script language fundamentals
Patterns for JVM languages - Geecon 2014
Javascript
JavaScript Tutorial
JavaScript Workshop
Advisor Jumpstart: JavaScript
Angular Mini-Challenges
Java script
МИХАЙЛО БОДНАРЧУК «SuperCharged End to End Testing with CodeceptJS» QADay 2019
JavaScript: DOM and jQuery
Ad

Viewers also liked (13)

DOCX
PPTX
Usaha kecil menengah( ukm ) erlina risnandari 11140131 ( 12 )
PDF
Evaluación diagnóstica por escuela
DOCX
Cuestionario Bransford
PDF
Photobook
DOCX
Historia a través de ideas
PPTX
Proyecto sena blog blogger blogspot
PPT
Kamil Presentation final
PDF
Programa electoral PABA 2011
PPTX
Guia instalacion gretl
PDF
外贸企业网站的定位和呈现(外贸企业定位)
PDF
Formación en didáctica tic. educación infantil
PPTX
Bidang Garapan Personalia
Usaha kecil menengah( ukm ) erlina risnandari 11140131 ( 12 )
Evaluación diagnóstica por escuela
Cuestionario Bransford
Photobook
Historia a través de ideas
Proyecto sena blog blogger blogspot
Kamil Presentation final
Programa electoral PABA 2011
Guia instalacion gretl
外贸企业网站的定位和呈现(外贸企业定位)
Formación en didáctica tic. educación infantil
Bidang Garapan Personalia
Ad

Similar to Java script basics (20)

PPTX
Web programming
PPT
Javascript sivasoft
DOCX
PDF
ABCs of Programming_eBook Contents
PPTX
IntroJavascript.pptx cjfjgjggkgutufjf7fjvit8t
PPTX
Learning space presentation1 learn Java script
PPT
Java Script ppt
PPTX
CSC PPT 12.pptx
PDF
Ch3- Java Script.pdf
PPTX
JavaScript Lecture notes.pptx
PPT
JAVA SCRIPT.pptbbdndndmdndndndndnndmmddnndn
PDF
PDF
8.-Javascript-report powerpoint presentation
PDF
internet Chapter 4-JavascripPrepare a ppt of video compression techniques bas...
PPTX
wp-UNIT_III.pptx
PPT
Html JavaScript and CSS
PDF
JavaScript
PPTX
Web designing unit 4
PPTX
My 70-480 HTML5 certification learning
PDF
Javascript
Web programming
Javascript sivasoft
ABCs of Programming_eBook Contents
IntroJavascript.pptx cjfjgjggkgutufjf7fjvit8t
Learning space presentation1 learn Java script
Java Script ppt
CSC PPT 12.pptx
Ch3- Java Script.pdf
JavaScript Lecture notes.pptx
JAVA SCRIPT.pptbbdndndmdndndndndnndmmddnndn
8.-Javascript-report powerpoint presentation
internet Chapter 4-JavascripPrepare a ppt of video compression techniques bas...
wp-UNIT_III.pptx
Html JavaScript and CSS
JavaScript
Web designing unit 4
My 70-480 HTML5 certification learning
Javascript

Recently uploaded (20)

PPTX
Big Data Technologies - Introduction.pptx
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
A comparative analysis of optical character recognition models for extracting...
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Machine learning based COVID-19 study performance prediction
PDF
Encapsulation theory and applications.pdf
PPTX
sap open course for s4hana steps from ECC to s4
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
A Presentation on Artificial Intelligence
PPT
Teaching material agriculture food technology
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Big Data Technologies - Introduction.pptx
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Building Integrated photovoltaic BIPV_UPV.pdf
Advanced methodologies resolving dimensionality complications for autism neur...
A comparative analysis of optical character recognition models for extracting...
Digital-Transformation-Roadmap-for-Companies.pptx
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Review of recent advances in non-invasive hemoglobin estimation
Diabetes mellitus diagnosis method based random forest with bat algorithm
Machine learning based COVID-19 study performance prediction
Encapsulation theory and applications.pdf
sap open course for s4hana steps from ECC to s4
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
20250228 LYD VKU AI Blended-Learning.pptx
A Presentation on Artificial Intelligence
Teaching material agriculture food technology
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Reach Out and Touch Someone: Haptics and Empathic Computing
gpt5_lecture_notes_comprehensive_20250812015547.pdf
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf

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: sales@iprismtech.com Thank you www.iprismtech.com