SlideShare a Scribd company logo
JavaScript Hello World: How to Write
Your First Program in JavaScript
OCTOBER 11, 2013 BY KASIA MIKOLUK
JavaScript is the engine that drives the
internet. Virtually every one of your favorite websites uses JavaScript in
some way or the other. From checking text input to creating alerts and
animations, JavaScript finds many uses on a web page.
Learning JavaScript is essential to becoming a front end web developer. It is
also one of the easier languages to pick up, making it ideal for beginners
looking to start their programming journey. This JavaScript prep
course will teach you how you can start using JavaScript on your websites.
In this tutorial, we will introduce you to some JavaScript programming
fundamentals and create our very first “Hello World” program.
What is JavaScript?
Wikipedia defines JavaScript or JS as an “interpreted programming
language” that allows “client-side scripts to interact with the user”.
It’s okay if all that sounded complete mumbo jumbo to you.
Let’s breakdown this definition into something a normal person could
understand:
 Interpreted Programming Language: Most programming
languages are either compiled or interpreted. A compiled
programming language must first go through an external compiler
before it can be executed. Most languages – Java, Python, Ruby, etc. –
are like that. There no such requirement for an interpreted
programming language. A program written in an interpreted
language can be run right away. For JavaScript, this means you can run
the program straight from the browser itself.
 Client-Side Script: All web programming can be divided into two
categories:client-side and server-side. A server-side program (or
script) is executed on the web server where web pages are actually
stored. A client-side program, on the other hand, is executed on the
user’s web browser itself. For JavaScript, this means the program is
executed as soon as the user downloads the webpage. You can learn
more about JavaScript client-side scripting in this course.
JavaScript is primarily used to create interactive elements on a web page.
Some of the most common uses of JavaScript are:
 Verifying data entered into a web form such as a sign-up or contact-us
form.
 Updating information on a webpage without refreshing it.
 DOM (Document Object Model) scripting. This is a fairly advanced way
to use JavaScript. Don’t worry about it now. We’ll get to it once you’re
comfortable with basic JavaScript.
 Creating alerts, new browser windows, etc.
 Creating animations through plugin libraries like jQuery.
As you can see, this covers the entire gamut of interactivity on any webpage.
JavaScript plugin libraries are especially useful in this context as they give
you access to advanced functions without requiring any coding on your part.
We’ll learn more about plugin libraries in later tutorials. For now, all you
should know is that JavaScript adds interactivity to a web page.
Caveat: JavaScript is Not Java
One of the first mistakes beginners make is assuming that JavaScript is a
simplified version of Java. It’s not. JavaScript is as different from Java as
chalk is from cheese. The only thing common between them are a few stray
syntax elements and the name itself.
Java, for the uninitiated, is a powerful object oriented programming
language used for creating complex, platform-independent (i.e. they can run
on any operation system) programs. JavaScript, on the other hand, can only
run programs within a web browser. Java is heavily used in business
software, while JavaScript is limited to use in web pages.
With that little confusion out of our way, let’s dive right into JavaScript
programming.
Hello World: Writing Your First JavaScript Program
“Hello World” is a staple of programming courses. The objective of this
program is simple: output the text “Hello World” on a computer screen.
Because of the simplicity of the message and syntax, it is usually the first
program taught to beginners.
Writing a “Hello World” program in JavaScript, as we will learn, is
exceptionally easy and requires not more than 3 lines of code.
Want to be a web developer? Learn how you can create complex websites
with JavaScript and become a web developer from scratch with this
course.
What You’ll Need
Since JavaScript is interpreted by the browser itself, we don’t need any fancy
compilers or additional software to write JS programs. All you need is:
 A text editor. Your humble Notepad will do just fine, but we highly
recommend Notepad++ (free).
 A web browser. You can use anything you want – Google Chrome,
Firefox, Internet Explorer or Safari.
Getting Started: Creating the HTML Framework
JavaScript programs are usually embedded within the web page itself. This
means they are written along with the HTML, though you can include them
externally as well.
To get started, we will first create a simple HTML file where we can include
our JavaScript.
Open your text editor and type the following code into it:
<!DOCTYPE HTML>
<html>
<head>
<title>JavaScript Hello World</title>
</head>
<body>
<h1>JavaScript Hello World Example</h1>
</body>
</html>
Save this file as test.html (make sure to save as ‘All Files’ if using Notepad).
This is a standard HTML template, nothing special about it. It should be
pretty clear to anyone with even a basic grasp of HTML.
Adding the JavaScript CodeAdding the JavaScript Code
We can now go ahead and write the JavaScript program.
Add the following code after the <h1> tag and save the file:
<script>
<alert(“Hello World!”)
<script>
That’s it! You’ve now successfully crated a JavaScript program.
Now use your web browser to open test.html. This is what you should see:
Easy, right?
All JavaScript code is written between <script></script> tags. We use ‘alert’
to create a function. The text to be displayed is written between quotes in
brackets.
But what if we wanted to create a separate “Hello World!” function we can
call anytime?
We can do that as well using just a few lines of code.
Creating a “Hello World” JavaScript Function
Programming 101: A function is any block of code that can be ‘called’ any
number of times within a program. Functions are extremely useful in
programming since you can create them once, use them n number of times.
We created a “Hello World!” alert box in the above example. Now we’ll create
a function that will create the same alert box whenever we want.
Type in the following code into your text file:
<!DOCTYPE HTML>
<html>
<head>
<script>
function myFunction()
{
alert(“Hello World!”)
}
</script>
</head>
<body>
</body>
</html>
Save this as test2.html.
Instead of adding the script in the <body>, we added the script to the
<head> and created a function called ‘helloWorld’. You can turn any piece of
code into a function by wrapping it in { } brackets and adding “function
functionName()” before it.
Now that we’ve created the function, we can call on it any number of times.
Add the following code anywhere between the <body></body> tags:
<p><button onclick="myFunction()">Create a Dialog Box!</button></p>
<p><button onclick="myFunction()">Create Another Dialog
Box!</button></p>
Click on either of the two buttons and you’ll see the “Hello World!” dialog
box pop up.

More Related Content

What's hot

Javascript
JavascriptJavascript
Javascript
Sushma M
 
Test
TestTest
Java script
Java scriptJava script
Java script
umesh patil
 
Nodejs
NodejsNodejs
Nodejs
dssprakash
 
Introduction to Java Script
Introduction to Java ScriptIntroduction to Java Script
Introduction to Java Script
Vijay Kumar Verma
 
Ijsphx927
Ijsphx927Ijsphx927
Ijsphx927
Thinkful
 
Time's Important - Let Task Management Save Yours
Time's Important - Let Task Management Save YoursTime's Important - Let Task Management Save Yours
Time's Important - Let Task Management Save Yours
James Bundey
 
Spring Boot
Spring BootSpring Boot
Spring Boot
Diego Pacheco
 
Reactjs workshop (1)
Reactjs workshop (1)Reactjs workshop (1)
Reactjs workshop (1)
Ahmed rebai
 
Going native with html5 web components
Going native with html5 web componentsGoing native with html5 web components
Going native with html5 web components
James York
 
Activity 5
Activity 5Activity 5
Activity 5
John Vincent Caño
 
Build a better(reactive) word press
Build a better(reactive) word pressBuild a better(reactive) word press
Build a better(reactive) word press
Bhushan Jawle
 
Kann JavaScript elegant sein?
Kann JavaScript elegant sein?Kann JavaScript elegant sein?
Kann JavaScript elegant sein?jbandi
 
Basic Concept of Node.js & NPM
Basic Concept of Node.js & NPMBasic Concept of Node.js & NPM
Basic Concept of Node.js & NPM
Bhargav Anadkat
 
Develop High Performance Windows 8 Application with HTML5 and JavaScriptHigh ...
Develop High Performance Windows 8 Application with HTML5 and JavaScriptHigh ...Develop High Performance Windows 8 Application with HTML5 and JavaScriptHigh ...
Develop High Performance Windows 8 Application with HTML5 and JavaScriptHigh ...
Doris Chen
 
Node
NodeNode
How fast can you onboard a new team member with VAGRANT ?
How fast can you onboard a new team member with VAGRANT ?How fast can you onboard a new team member with VAGRANT ?
How fast can you onboard a new team member with VAGRANT ?
Vivek Parihar
 
Java & JavaScript: Best Friends?
Java & JavaScript: Best Friends?Java & JavaScript: Best Friends?
Java & JavaScript: Best Friends?
jbandi
 
Node js
Node jsNode js
Progressive Web Apps – the return of the web? Goto Berlin 2016
Progressive Web Apps – the return of the web? Goto Berlin 2016Progressive Web Apps – the return of the web? Goto Berlin 2016
Progressive Web Apps – the return of the web? Goto Berlin 2016
Christian Heilmann
 

What's hot (20)

Javascript
JavascriptJavascript
Javascript
 
Test
TestTest
Test
 
Java script
Java scriptJava script
Java script
 
Nodejs
NodejsNodejs
Nodejs
 
Introduction to Java Script
Introduction to Java ScriptIntroduction to Java Script
Introduction to Java Script
 
Ijsphx927
Ijsphx927Ijsphx927
Ijsphx927
 
Time's Important - Let Task Management Save Yours
Time's Important - Let Task Management Save YoursTime's Important - Let Task Management Save Yours
Time's Important - Let Task Management Save Yours
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Reactjs workshop (1)
Reactjs workshop (1)Reactjs workshop (1)
Reactjs workshop (1)
 
Going native with html5 web components
Going native with html5 web componentsGoing native with html5 web components
Going native with html5 web components
 
Activity 5
Activity 5Activity 5
Activity 5
 
Build a better(reactive) word press
Build a better(reactive) word pressBuild a better(reactive) word press
Build a better(reactive) word press
 
Kann JavaScript elegant sein?
Kann JavaScript elegant sein?Kann JavaScript elegant sein?
Kann JavaScript elegant sein?
 
Basic Concept of Node.js & NPM
Basic Concept of Node.js & NPMBasic Concept of Node.js & NPM
Basic Concept of Node.js & NPM
 
Develop High Performance Windows 8 Application with HTML5 and JavaScriptHigh ...
Develop High Performance Windows 8 Application with HTML5 and JavaScriptHigh ...Develop High Performance Windows 8 Application with HTML5 and JavaScriptHigh ...
Develop High Performance Windows 8 Application with HTML5 and JavaScriptHigh ...
 
Node
NodeNode
Node
 
How fast can you onboard a new team member with VAGRANT ?
How fast can you onboard a new team member with VAGRANT ?How fast can you onboard a new team member with VAGRANT ?
How fast can you onboard a new team member with VAGRANT ?
 
Java & JavaScript: Best Friends?
Java & JavaScript: Best Friends?Java & JavaScript: Best Friends?
Java & JavaScript: Best Friends?
 
Node js
Node jsNode js
Node js
 
Progressive Web Apps – the return of the web? Goto Berlin 2016
Progressive Web Apps – the return of the web? Goto Berlin 2016Progressive Web Apps – the return of the web? Goto Berlin 2016
Progressive Web Apps – the return of the web? Goto Berlin 2016
 

Viewers also liked

Exposicion 1
Exposicion 1Exposicion 1
Exposicion 1
Edward Freire
 
adjectives to nouns
adjectives to nounsadjectives to nouns
adjectives to nouns
Jennifer Flores
 
Front and in
Front and inFront and in
Front and in
Pato Castillo
 
Radioastronomia amatoriale e radiotelescopi
Radioastronomia amatoriale e radiotelescopiRadioastronomia amatoriale e radiotelescopi
Radioastronomia amatoriale e radiotelescopi
Flavio Falcinelli
 
Henrique fleming introdução aos tensores
Henrique fleming   introdução aos tensoresHenrique fleming   introdução aos tensores
Henrique fleming introdução aos tensores
Franfisik Fisica
 
Academic Resources Commons Three Rivers
Academic Resources Commons Three Rivers Academic Resources Commons Three Rivers
Academic Resources Commons Three Rivers
cadams1977
 
Ph determinants
Ph determinantsPh determinants
Ph determinants
Jamory
 
Georgia court improvement project (cip)
Georgia court improvement project (cip)Georgia court improvement project (cip)
Georgia court improvement project (cip)
screaminc
 
scabies 66 pages part 2 of 4 john g. davidoff
scabies 66 pages part 2 of 4 john g. davidoffscabies 66 pages part 2 of 4 john g. davidoff
scabies 66 pages part 2 of 4 john g. davidoffjohn davidoff
 
Cl project 3 residential landscape project march 2015
Cl project 3 residential landscape project march 2015Cl project 3 residential landscape project march 2015
Cl project 3 residential landscape project march 2015
Lau Hui Ming Belinda
 
Excel 2010 bible
Excel 2010 bibleExcel 2010 bible
Excel 2010 bible
walled ashwah
 
Crescita Di Wikipedia
Crescita Di WikipediaCrescita Di Wikipedia
Crescita Di Wikipedia
orgest shehaj
 
From and in
From and in From and in
From and in
Ronald Marroquin
 

Viewers also liked (15)

Exposicion 1
Exposicion 1Exposicion 1
Exposicion 1
 
adjectives to nouns
adjectives to nounsadjectives to nouns
adjectives to nouns
 
R.Couture
R.CoutureR.Couture
R.Couture
 
Front and in
Front and inFront and in
Front and in
 
Radioastronomia amatoriale e radiotelescopi
Radioastronomia amatoriale e radiotelescopiRadioastronomia amatoriale e radiotelescopi
Radioastronomia amatoriale e radiotelescopi
 
Henrique fleming introdução aos tensores
Henrique fleming   introdução aos tensoresHenrique fleming   introdução aos tensores
Henrique fleming introdução aos tensores
 
Scarlett Fashion
Scarlett FashionScarlett Fashion
Scarlett Fashion
 
Academic Resources Commons Three Rivers
Academic Resources Commons Three Rivers Academic Resources Commons Three Rivers
Academic Resources Commons Three Rivers
 
Ph determinants
Ph determinantsPh determinants
Ph determinants
 
Georgia court improvement project (cip)
Georgia court improvement project (cip)Georgia court improvement project (cip)
Georgia court improvement project (cip)
 
scabies 66 pages part 2 of 4 john g. davidoff
scabies 66 pages part 2 of 4 john g. davidoffscabies 66 pages part 2 of 4 john g. davidoff
scabies 66 pages part 2 of 4 john g. davidoff
 
Cl project 3 residential landscape project march 2015
Cl project 3 residential landscape project march 2015Cl project 3 residential landscape project march 2015
Cl project 3 residential landscape project march 2015
 
Excel 2010 bible
Excel 2010 bibleExcel 2010 bible
Excel 2010 bible
 
Crescita Di Wikipedia
Crescita Di WikipediaCrescita Di Wikipedia
Crescita Di Wikipedia
 
From and in
From and in From and in
From and in
 

Similar to Java script hello world

Basics java scripts
Basics java scriptsBasics java scripts
Basics java scriptsch samaram
 
Unit 4 Java script.pptx
Unit 4 Java script.pptxUnit 4 Java script.pptx
Unit 4 Java script.pptx
Gangesh8
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />tutorialsruby
 
Essential_Javascript_--_A_Javascript_Tutorial
Essential_Javascript_--_A_Javascript_TutorialEssential_Javascript_--_A_Javascript_Tutorial
Essential_Javascript_--_A_Javascript_Tutorialtutorialsruby
 
Essential Javascript -- A Javascript &lt;b>Tutorial&lt;/b>
Essential Javascript -- A Javascript &lt;b>Tutorial&lt;/b>Essential Javascript -- A Javascript &lt;b>Tutorial&lt;/b>
Essential Javascript -- A Javascript &lt;b>Tutorial&lt;/b>tutorialsruby
 
Essential_Javascript_--_A_Javascript_Tutorial
Essential_Javascript_--_A_Javascript_TutorialEssential_Javascript_--_A_Javascript_Tutorial
Essential_Javascript_--_A_Javascript_Tutorialtutorialsruby
 
4007655 introduction-to-javascript
4007655 introduction-to-javascript4007655 introduction-to-javascript
4007655 introduction-to-javascript
Vikash Chandra
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
ApxicTechnologies1
 
LabsLab8.htmlLab 8 Im Thinking of a NumberBefore yo.docx
LabsLab8.htmlLab 8 Im Thinking of a NumberBefore yo.docxLabsLab8.htmlLab 8 Im Thinking of a NumberBefore yo.docx
LabsLab8.htmlLab 8 Im Thinking of a NumberBefore yo.docx
DIPESH30
 
WEB PROGRAMMING UNIT II BY BHAVSINGH MALOTH
WEB PROGRAMMING UNIT II BY BHAVSINGH MALOTHWEB PROGRAMMING UNIT II BY BHAVSINGH MALOTH
WEB PROGRAMMING UNIT II BY BHAVSINGH MALOTH
Bhavsingh Maloth
 
Web programming UNIT II by Bhavsingh Maloth
Web programming UNIT II by Bhavsingh MalothWeb programming UNIT II by Bhavsingh Maloth
Web programming UNIT II by Bhavsingh Maloth
Bhavsingh Maloth
 
JavaScript - Getting Started.pptx
JavaScript - Getting Started.pptxJavaScript - Getting Started.pptx
JavaScript - Getting Started.pptx
JonnJorellPunto
 
Java script Basic
Java script BasicJava script Basic
Java script Basic
Jaya Kumari
 
Progressive Web Application by Citytech
Progressive Web Application by CitytechProgressive Web Application by Citytech
Progressive Web Application by Citytech
Ritwik Das
 
Javascript - Ebook (A Quick Guide)
Javascript - Ebook (A Quick Guide)Javascript - Ebook (A Quick Guide)
Javascript - Ebook (A Quick Guide)
sourav newatia
 
Fewd week4 slides
Fewd week4 slidesFewd week4 slides
Fewd week4 slides
William Myers
 
JavaScript Core fundamentals - Learn JavaScript Here
JavaScript Core fundamentals - Learn JavaScript HereJavaScript Core fundamentals - Learn JavaScript Here
JavaScript Core fundamentals - Learn JavaScript Here
Laurence Svekis ✔
 
Step by Step Guide on Essay Format in APA For Beginners
Step by Step Guide on Essay Format in APA For BeginnersStep by Step Guide on Essay Format in APA For Beginners
Step by Step Guide on Essay Format in APA For Beginners
calltutors
 
Basic JavaScript Tutorial
Basic JavaScript TutorialBasic JavaScript Tutorial
Basic JavaScript Tutorial
DHTMLExtreme
 

Similar to Java script hello world (20)

Basics java scripts
Basics java scriptsBasics java scripts
Basics java scripts
 
Unit 4 Java script.pptx
Unit 4 Java script.pptxUnit 4 Java script.pptx
Unit 4 Java script.pptx
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />
 
Essential_Javascript_--_A_Javascript_Tutorial
Essential_Javascript_--_A_Javascript_TutorialEssential_Javascript_--_A_Javascript_Tutorial
Essential_Javascript_--_A_Javascript_Tutorial
 
Essential Javascript -- A Javascript &lt;b>Tutorial&lt;/b>
Essential Javascript -- A Javascript &lt;b>Tutorial&lt;/b>Essential Javascript -- A Javascript &lt;b>Tutorial&lt;/b>
Essential Javascript -- A Javascript &lt;b>Tutorial&lt;/b>
 
Essential_Javascript_--_A_Javascript_Tutorial
Essential_Javascript_--_A_Javascript_TutorialEssential_Javascript_--_A_Javascript_Tutorial
Essential_Javascript_--_A_Javascript_Tutorial
 
Javascript tutorial
Javascript tutorialJavascript tutorial
Javascript tutorial
 
4007655 introduction-to-javascript
4007655 introduction-to-javascript4007655 introduction-to-javascript
4007655 introduction-to-javascript
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
 
LabsLab8.htmlLab 8 Im Thinking of a NumberBefore yo.docx
LabsLab8.htmlLab 8 Im Thinking of a NumberBefore yo.docxLabsLab8.htmlLab 8 Im Thinking of a NumberBefore yo.docx
LabsLab8.htmlLab 8 Im Thinking of a NumberBefore yo.docx
 
WEB PROGRAMMING UNIT II BY BHAVSINGH MALOTH
WEB PROGRAMMING UNIT II BY BHAVSINGH MALOTHWEB PROGRAMMING UNIT II BY BHAVSINGH MALOTH
WEB PROGRAMMING UNIT II BY BHAVSINGH MALOTH
 
Web programming UNIT II by Bhavsingh Maloth
Web programming UNIT II by Bhavsingh MalothWeb programming UNIT II by Bhavsingh Maloth
Web programming UNIT II by Bhavsingh Maloth
 
JavaScript - Getting Started.pptx
JavaScript - Getting Started.pptxJavaScript - Getting Started.pptx
JavaScript - Getting Started.pptx
 
Java script Basic
Java script BasicJava script Basic
Java script Basic
 
Progressive Web Application by Citytech
Progressive Web Application by CitytechProgressive Web Application by Citytech
Progressive Web Application by Citytech
 
Javascript - Ebook (A Quick Guide)
Javascript - Ebook (A Quick Guide)Javascript - Ebook (A Quick Guide)
Javascript - Ebook (A Quick Guide)
 
Fewd week4 slides
Fewd week4 slidesFewd week4 slides
Fewd week4 slides
 
JavaScript Core fundamentals - Learn JavaScript Here
JavaScript Core fundamentals - Learn JavaScript HereJavaScript Core fundamentals - Learn JavaScript Here
JavaScript Core fundamentals - Learn JavaScript Here
 
Step by Step Guide on Essay Format in APA For Beginners
Step by Step Guide on Essay Format in APA For BeginnersStep by Step Guide on Essay Format in APA For Beginners
Step by Step Guide on Essay Format in APA For Beginners
 
Basic JavaScript Tutorial
Basic JavaScript TutorialBasic JavaScript Tutorial
Basic JavaScript Tutorial
 

Java script hello world

  • 1. JavaScript Hello World: How to Write Your First Program in JavaScript OCTOBER 11, 2013 BY KASIA MIKOLUK JavaScript is the engine that drives the internet. Virtually every one of your favorite websites uses JavaScript in some way or the other. From checking text input to creating alerts and animations, JavaScript finds many uses on a web page. Learning JavaScript is essential to becoming a front end web developer. It is also one of the easier languages to pick up, making it ideal for beginners looking to start their programming journey. This JavaScript prep course will teach you how you can start using JavaScript on your websites. In this tutorial, we will introduce you to some JavaScript programming fundamentals and create our very first “Hello World” program. What is JavaScript? Wikipedia defines JavaScript or JS as an “interpreted programming language” that allows “client-side scripts to interact with the user”. It’s okay if all that sounded complete mumbo jumbo to you. Let’s breakdown this definition into something a normal person could understand:
  • 2.  Interpreted Programming Language: Most programming languages are either compiled or interpreted. A compiled programming language must first go through an external compiler before it can be executed. Most languages – Java, Python, Ruby, etc. – are like that. There no such requirement for an interpreted programming language. A program written in an interpreted language can be run right away. For JavaScript, this means you can run the program straight from the browser itself.  Client-Side Script: All web programming can be divided into two categories:client-side and server-side. A server-side program (or script) is executed on the web server where web pages are actually stored. A client-side program, on the other hand, is executed on the user’s web browser itself. For JavaScript, this means the program is executed as soon as the user downloads the webpage. You can learn more about JavaScript client-side scripting in this course. JavaScript is primarily used to create interactive elements on a web page. Some of the most common uses of JavaScript are:  Verifying data entered into a web form such as a sign-up or contact-us form.  Updating information on a webpage without refreshing it.  DOM (Document Object Model) scripting. This is a fairly advanced way to use JavaScript. Don’t worry about it now. We’ll get to it once you’re comfortable with basic JavaScript.  Creating alerts, new browser windows, etc.  Creating animations through plugin libraries like jQuery. As you can see, this covers the entire gamut of interactivity on any webpage. JavaScript plugin libraries are especially useful in this context as they give you access to advanced functions without requiring any coding on your part. We’ll learn more about plugin libraries in later tutorials. For now, all you should know is that JavaScript adds interactivity to a web page. Caveat: JavaScript is Not Java One of the first mistakes beginners make is assuming that JavaScript is a simplified version of Java. It’s not. JavaScript is as different from Java as
  • 3. chalk is from cheese. The only thing common between them are a few stray syntax elements and the name itself. Java, for the uninitiated, is a powerful object oriented programming language used for creating complex, platform-independent (i.e. they can run on any operation system) programs. JavaScript, on the other hand, can only run programs within a web browser. Java is heavily used in business software, while JavaScript is limited to use in web pages. With that little confusion out of our way, let’s dive right into JavaScript programming. Hello World: Writing Your First JavaScript Program “Hello World” is a staple of programming courses. The objective of this program is simple: output the text “Hello World” on a computer screen. Because of the simplicity of the message and syntax, it is usually the first program taught to beginners. Writing a “Hello World” program in JavaScript, as we will learn, is exceptionally easy and requires not more than 3 lines of code. Want to be a web developer? Learn how you can create complex websites with JavaScript and become a web developer from scratch with this course. What You’ll Need Since JavaScript is interpreted by the browser itself, we don’t need any fancy compilers or additional software to write JS programs. All you need is:  A text editor. Your humble Notepad will do just fine, but we highly recommend Notepad++ (free).
  • 4.  A web browser. You can use anything you want – Google Chrome, Firefox, Internet Explorer or Safari. Getting Started: Creating the HTML Framework JavaScript programs are usually embedded within the web page itself. This means they are written along with the HTML, though you can include them externally as well. To get started, we will first create a simple HTML file where we can include our JavaScript. Open your text editor and type the following code into it: <!DOCTYPE HTML> <html> <head> <title>JavaScript Hello World</title> </head> <body> <h1>JavaScript Hello World Example</h1> </body> </html> Save this file as test.html (make sure to save as ‘All Files’ if using Notepad).
  • 5. This is a standard HTML template, nothing special about it. It should be pretty clear to anyone with even a basic grasp of HTML. Adding the JavaScript CodeAdding the JavaScript Code We can now go ahead and write the JavaScript program. Add the following code after the <h1> tag and save the file: <script> <alert(“Hello World!”) <script> That’s it! You’ve now successfully crated a JavaScript program. Now use your web browser to open test.html. This is what you should see: Easy, right? All JavaScript code is written between <script></script> tags. We use ‘alert’ to create a function. The text to be displayed is written between quotes in brackets. But what if we wanted to create a separate “Hello World!” function we can call anytime?
  • 6. We can do that as well using just a few lines of code. Creating a “Hello World” JavaScript Function Programming 101: A function is any block of code that can be ‘called’ any number of times within a program. Functions are extremely useful in programming since you can create them once, use them n number of times. We created a “Hello World!” alert box in the above example. Now we’ll create a function that will create the same alert box whenever we want. Type in the following code into your text file: <!DOCTYPE HTML> <html> <head> <script> function myFunction() { alert(“Hello World!”) } </script> </head> <body> </body> </html> Save this as test2.html.
  • 7. Instead of adding the script in the <body>, we added the script to the <head> and created a function called ‘helloWorld’. You can turn any piece of code into a function by wrapping it in { } brackets and adding “function functionName()” before it. Now that we’ve created the function, we can call on it any number of times. Add the following code anywhere between the <body></body> tags: <p><button onclick="myFunction()">Create a Dialog Box!</button></p> <p><button onclick="myFunction()">Create Another Dialog Box!</button></p>
  • 8. Click on either of the two buttons and you’ll see the “Hello World!” dialog box pop up.