SlideShare a Scribd company logo
Javascript Survival for Honesty and Humility What is Javascript? ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],What can a JavaScript do? ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Program Example: <html> <body> <script type=&quot;text/javascript&quot;> document.write(&quot;Hello World!&quot;); </script> </body> </html>  Output:
Where to put Javascript? Javascript in a page will be executed immediately while the page loads into the browser. This is not always what we want. Sometimes we want to execute a script when a page loads, or at a later event, such as when a user clicks a button.  a. Scripts in <head> <html> <head> <script type=&quot;text/javascript&quot;> function message() { alert(&quot;This alert box was called with the onload event&quot;); } </script> </head> <body onload=&quot;message()&quot;> </body> </html>  Input Program:   Output Program:
b. Scripts in <body> Input Program:   Output Program: <html> <head> </head> <body> <script type=&quot;text/javascript&quot;> document.write(&quot;This message is written by JavaScript&quot;); </script> </body> </html>
c. Scripts in <head> and <body> Input Program:   Output Program: <html> <head> <script type=&quot;text/javascript&quot;> function message() { alert(&quot;This alert box was called with the onload event&quot;); } </script> </head> <body onload=&quot;message()&quot;> <script type=&quot;text/javascript&quot;> document.write(&quot;This message is written by JavaScript&quot;); </script> </body> </html>
Rules in Javascript ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Javascript Variables As with algebra, JavaScript variables are used to hold values or expressions. A variable can have a short name, like x, or a more descriptive name, like carname. Rules for JavaScript variable names: Variable names are case sensitive (y and Y are two different variables)  Variable names must begin with a letter or the underscore character  Note:  Because JavaScript is case-sensitive, variable names are case-sensitive. Declaring (or creating) Javascript Variables var x; var carname;  Assigning Values to Undeclare Javascript Variables var x=5; var carname=“Toyota”;  var x=5; var carname=“Toyota”;  You can use the assigned values when you declare them:  x=5; carname=“Toyota”;  has same effect as…
Redeclaring Javascript Variables var x=5; var x;  After the execution of the statements above, the variable x will still have the value of 5. The value of x is not reset (or cleared) when you redeclare it.  Javascript Arithmetic y=x-5; z=y+3;
Javascript  Arithmetic Operators
Javascript  Assignment Operators
The + Operator Used on Strings txt1=&quot;What a very&quot;; txt2=&quot;nice day&quot;; txt3=txt1+txt2; Input Program:   Output Program: What a very nice day Comparison Operators
Logical Operators Syntax: variablename=(condition)?value1:value2  Example: greeting=(visitor==&quot;PRES&quot;)?&quot;Dear President &quot;:&quot;Dear &quot;; Result: “ Dear President” or else “Dear” Conditional Operators

More Related Content

What's hot

Java scripts
Java scriptsJava scripts
Java scripts
Capgemini India
 
Java Script
Java ScriptJava Script
Java Script
husbancom
 
Java script
Java scriptJava script
Java script
ITz_1
 
Basics of Javascript
Basics of Javascript Basics of Javascript
Basics of Javascript
poojanov04
 
JavaScript - Part-1
JavaScript - Part-1JavaScript - Part-1
JavaScript - Part-1
Jainul Musani
 
HTML Introduction
HTML IntroductionHTML Introduction
HTML Introduction
Jainul Musani
 
Razor new view engine asp.net
Razor new view engine asp.netRazor new view engine asp.net
Razor new view engine asp.net
ahsanmm
 
Javascript
JavascriptJavascript
Javascript
Nagarajan
 
Introduction to Java Script
Introduction to Java ScriptIntroduction to Java Script
Introduction to Java Script
Vijay Kumar Verma
 
Scripting languages
Scripting languagesScripting languages
Scripting languages
teach4uin
 
JavaScript Introduction
JavaScript IntroductionJavaScript Introduction
JavaScript Introduction
Jainul Musani
 
Java script
Java scriptJava script
Java script
umesh patil
 
Web topic 21 pass info via javascript
Web topic 21  pass info via javascriptWeb topic 21  pass info via javascript
Web topic 21 pass info via javascriptCK Yang
 
Java script
Java scriptJava script
Java script
reddivarihareesh
 
Introduction to javaScript
Introduction to javaScriptIntroduction to javaScript
Introduction to javaScriptNeil Ghosh
 
Java Servlets Part 2
Java Servlets Part 2Java Servlets Part 2
Java Servlets Part 2
Gurpreet singh
 
Java script
Java scriptJava script
Java script
Rajkiran Mummadi
 
Coder Presentation
Coder  PresentationCoder  Presentation
Coder PresentationDoug Green
 

What's hot (20)

Java scripts
Java scriptsJava scripts
Java scripts
 
Java Script
Java ScriptJava Script
Java Script
 
Unit 2.4
Unit 2.4Unit 2.4
Unit 2.4
 
Java script
Java scriptJava script
Java script
 
Basics of Javascript
Basics of Javascript Basics of Javascript
Basics of Javascript
 
JavaScript - Part-1
JavaScript - Part-1JavaScript - Part-1
JavaScript - Part-1
 
HTML Introduction
HTML IntroductionHTML Introduction
HTML Introduction
 
Razor new view engine asp.net
Razor new view engine asp.netRazor new view engine asp.net
Razor new view engine asp.net
 
Javascript
JavascriptJavascript
Javascript
 
Introduction to Java Script
Introduction to Java ScriptIntroduction to Java Script
Introduction to Java Script
 
Scripting languages
Scripting languagesScripting languages
Scripting languages
 
JavaScript Introduction
JavaScript IntroductionJavaScript Introduction
JavaScript Introduction
 
Client side scripting
Client side scriptingClient side scripting
Client side scripting
 
Java script
Java scriptJava script
Java script
 
Web topic 21 pass info via javascript
Web topic 21  pass info via javascriptWeb topic 21  pass info via javascript
Web topic 21 pass info via javascript
 
Java script
Java scriptJava script
Java script
 
Introduction to javaScript
Introduction to javaScriptIntroduction to javaScript
Introduction to javaScript
 
Java Servlets Part 2
Java Servlets Part 2Java Servlets Part 2
Java Servlets Part 2
 
Java script
Java scriptJava script
Java script
 
Coder Presentation
Coder  PresentationCoder  Presentation
Coder Presentation
 

Viewers also liked

ศิลปะฉับพลัน54
ศิลปะฉับพลัน54ศิลปะฉับพลัน54
ศิลปะฉับพลัน54sdsdsds
 
Third year CSBN presentation 2nd quarter - flash gui
Third year CSBN presentation   2nd quarter - flash guiThird year CSBN presentation   2nd quarter - flash gui
Third year CSBN presentation 2nd quarter - flash gui
Andy de Vera
 
Javascript survival2
Javascript survival2Javascript survival2
Javascript survival2
Andy de Vera
 
Jason Javier- Hero
Jason Javier- HeroJason Javier- Hero
Jason Javier- Hero
MeltandFreeze01
 
กลุ่ม54 ศิลปะฉับพลัน
กลุ่ม54  ศิลปะฉับพลันกลุ่ม54  ศิลปะฉับพลัน
กลุ่ม54 ศิลปะฉับพลันsdsdsds
 

Viewers also liked (6)

ศิลปะฉับพลัน54
ศิลปะฉับพลัน54ศิลปะฉับพลัน54
ศิลปะฉับพลัน54
 
Third year CSBN presentation 2nd quarter - flash gui
Third year CSBN presentation   2nd quarter - flash guiThird year CSBN presentation   2nd quarter - flash gui
Third year CSBN presentation 2nd quarter - flash gui
 
Bērnu žūrija 2010
Bērnu žūrija 2010Bērnu žūrija 2010
Bērnu žūrija 2010
 
Javascript survival2
Javascript survival2Javascript survival2
Javascript survival2
 
Jason Javier- Hero
Jason Javier- HeroJason Javier- Hero
Jason Javier- Hero
 
กลุ่ม54 ศิลปะฉับพลัน
กลุ่ม54  ศิลปะฉับพลันกลุ่ม54  ศิลปะฉับพลัน
กลุ่ม54 ศิลปะฉับพลัน
 

Similar to Javascript survival for CSBN Sophomores

Introduction to Java Scripting
Introduction to Java ScriptingIntroduction to Java Scripting
Introduction to Java Scripting
fantasticdigitaltools
 
Introduction to java script
Introduction to java scriptIntroduction to java script
Introduction to java script
nanjil1984
 
Jquery 1
Jquery 1Jquery 1
Javascript
JavascriptJavascript
Javascript
mussawir20
 
JavaScript & Dom Manipulation
JavaScript & Dom ManipulationJavaScript & Dom Manipulation
JavaScript & Dom Manipulation
Mohammed Arif
 
Web programming
Web programmingWeb programming
Web programming
Leo Mark Villar
 
Javascript tutorial
Javascript tutorialJavascript tutorial
Javascript tutorial
Avinash Malhotra
 
Java script Basic
Java script BasicJava script Basic
Java script Basic
Jaya Kumari
 
Introduction to Javascript
Introduction to JavascriptIntroduction to Javascript
Introduction to Javascript
ambuj pathak
 
JavaScript - Getting Started.pptx
JavaScript - Getting Started.pptxJavaScript - Getting Started.pptx
JavaScript - Getting Started.pptx
JonnJorellPunto
 
Java script by Act Academy
Java script by Act AcademyJava script by Act Academy
Java script by Act Academy
actanimation
 
JavaScript_III.pptx
JavaScript_III.pptxJavaScript_III.pptx
JavaScript_III.pptx
rashmiisrani1
 
Java scipt
Java sciptJava scipt
Basic Java script handouts for students
Basic Java script handouts for students Basic Java script handouts for students
Basic Java script handouts for students
shafiq sangi
 
JavaScript with Syntax & Implementation
JavaScript with Syntax & ImplementationJavaScript with Syntax & Implementation
JavaScript with Syntax & Implementation
Soumen Santra
 

Similar to Javascript survival for CSBN Sophomores (20)

Introduction to Java Scripting
Introduction to Java ScriptingIntroduction to Java Scripting
Introduction to Java Scripting
 
Introduction to java script
Introduction to java scriptIntroduction to java script
Introduction to java script
 
Javascript
JavascriptJavascript
Javascript
 
Jquery 1
Jquery 1Jquery 1
Jquery 1
 
Javascript
JavascriptJavascript
Javascript
 
Unit 2.4
Unit 2.4Unit 2.4
Unit 2.4
 
JavaScript & Dom Manipulation
JavaScript & Dom ManipulationJavaScript & Dom Manipulation
JavaScript & Dom Manipulation
 
Web programming
Web programmingWeb programming
Web programming
 
Javascript tutorial
Javascript tutorialJavascript tutorial
Javascript tutorial
 
Java script Basic
Java script BasicJava script Basic
Java script Basic
 
Tugas Pw [6]
Tugas Pw [6]Tugas Pw [6]
Tugas Pw [6]
 
Tugas Pw [6] (2)
Tugas Pw [6] (2)Tugas Pw [6] (2)
Tugas Pw [6] (2)
 
Introduction to Javascript
Introduction to JavascriptIntroduction to Javascript
Introduction to Javascript
 
JavaScript - Getting Started.pptx
JavaScript - Getting Started.pptxJavaScript - Getting Started.pptx
JavaScript - Getting Started.pptx
 
JavaScript
JavaScriptJavaScript
JavaScript
 
Java script by Act Academy
Java script by Act AcademyJava script by Act Academy
Java script by Act Academy
 
JavaScript_III.pptx
JavaScript_III.pptxJavaScript_III.pptx
JavaScript_III.pptx
 
Java scipt
Java sciptJava scipt
Java scipt
 
Basic Java script handouts for students
Basic Java script handouts for students Basic Java script handouts for students
Basic Java script handouts for students
 
JavaScript with Syntax & Implementation
JavaScript with Syntax & ImplementationJavaScript with Syntax & Implementation
JavaScript with Syntax & Implementation
 

Recently uploaded

Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
timhan337
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBCSTRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
kimdan468
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
Scholarhat
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 

Recently uploaded (20)

Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBCSTRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 

Javascript survival for CSBN Sophomores

  • 1.
  • 2. Program Example: <html> <body> <script type=&quot;text/javascript&quot;> document.write(&quot;Hello World!&quot;); </script> </body> </html> Output:
  • 3. Where to put Javascript? Javascript in a page will be executed immediately while the page loads into the browser. This is not always what we want. Sometimes we want to execute a script when a page loads, or at a later event, such as when a user clicks a button. a. Scripts in <head> <html> <head> <script type=&quot;text/javascript&quot;> function message() { alert(&quot;This alert box was called with the onload event&quot;); } </script> </head> <body onload=&quot;message()&quot;> </body> </html> Input Program: Output Program:
  • 4. b. Scripts in <body> Input Program: Output Program: <html> <head> </head> <body> <script type=&quot;text/javascript&quot;> document.write(&quot;This message is written by JavaScript&quot;); </script> </body> </html>
  • 5. c. Scripts in <head> and <body> Input Program: Output Program: <html> <head> <script type=&quot;text/javascript&quot;> function message() { alert(&quot;This alert box was called with the onload event&quot;); } </script> </head> <body onload=&quot;message()&quot;> <script type=&quot;text/javascript&quot;> document.write(&quot;This message is written by JavaScript&quot;); </script> </body> </html>
  • 6.
  • 7. Javascript Variables As with algebra, JavaScript variables are used to hold values or expressions. A variable can have a short name, like x, or a more descriptive name, like carname. Rules for JavaScript variable names: Variable names are case sensitive (y and Y are two different variables) Variable names must begin with a letter or the underscore character Note: Because JavaScript is case-sensitive, variable names are case-sensitive. Declaring (or creating) Javascript Variables var x; var carname; Assigning Values to Undeclare Javascript Variables var x=5; var carname=“Toyota”; var x=5; var carname=“Toyota”; You can use the assigned values when you declare them: x=5; carname=“Toyota”; has same effect as…
  • 8. Redeclaring Javascript Variables var x=5; var x; After the execution of the statements above, the variable x will still have the value of 5. The value of x is not reset (or cleared) when you redeclare it. Javascript Arithmetic y=x-5; z=y+3;
  • 11. The + Operator Used on Strings txt1=&quot;What a very&quot;; txt2=&quot;nice day&quot;; txt3=txt1+txt2; Input Program: Output Program: What a very nice day Comparison Operators
  • 12. Logical Operators Syntax: variablename=(condition)?value1:value2  Example: greeting=(visitor==&quot;PRES&quot;)?&quot;Dear President &quot;:&quot;Dear &quot;; Result: “ Dear President” or else “Dear” Conditional Operators