Introduction To Java Scripts: Javascript Origins
Introduction To Java Scripts: Javascript Origins
com
What is JavaScript
ed
uc
at
io
n.
co
m
JavaScript Origins
JavaScript was invented by Netscape and Sun
Microsystems in 1995. JavaScript and Java both are
different.
hi
.s
a
ks
w
w
www.sakshieducation.com
www.sakshieducation.com
SCRIPT Tag
The <script> label alarms a program that Javascript code takes
after. It is ordinarily inserted in the HTML
</SCRIPT>
ed
uc
at
io
n.
SCRIPT Example
Create index.html page
Write the below example code
co
m
w
w
.s
a
ks
hi
www.sakshieducation.com
www.sakshieducation.com
Executing Javascript
There are three ways to add JavaScript commands to your Web Pages.
Embedding code
Inline code
External file
ed
uc
at
io
n.
co
m
Embedding code
You can insert Javascript in a HTML archive as articulations and
capacities inside a <script> tag, by detailing a document as the
Javascript source, by defining a Javascript interpretation as the
estimation of a HTML property or as occasion handlers inside certain
other HTML labels.
Embedding Example
Create index.html page
Write the below example code
w
w
.s
a
ks
hi
www.sakshieducation.com
www.sakshieducation.com
first
Inline
java
script
.s
a
ks
hi
ed
uc
at
io
n.
Inline Example
Create index.html page
Write the below example code
<button onclick= "alert ('My
program')">Click</button>
Save that html file
Open that file with browser
The output of the html file is
co
m
Inline code
You can insert Javascript in a HTML archive as articulations and
capacities inside any tag, by detailing an event i.e. onclick and
ondblclick.
w
w
External File
You can utilize the SRC characteristic of the <script> tag to call
Javascript code from an outside content record. This is helpful in the
event that you have a great deal of code or you need to run it from a few
pages, in light of the fact that any number of pages can call the same
outside Javascript document. The content document itself contains no
HTML labels. It is called by the following tag:
www.sakshieducation.com
www.sakshieducation.com
ed
uc
at
io
n.
co
m
External Example
Create index.html page
Write the below example code
<SCRIPT SRC="script.js" language = "JavaScript"></SCRIPT>
Save that html file
Inside the script.js file is
alert("My first External java script program");
w
w
.s
a
ks
hi
www.sakshieducation.com
www.sakshieducation.com
co
m
ed
uc
at
io
n.
hi
Built-In Objects
A portion of the built-in language objects of Javascript offer more
advanced operations, for example:
Math provides for math calculations
Date provides date and time information
String provides for string manipulation
.s
a
ks
Math Object
The Math object gives methods to numerous numerical calculations,
including
Eg: abs(), log(), pow(), random(), round(), sqrt()
Syntax: math.method(#)
Example
w
w
www.sakshieducation.com
www.sakshieducation.com
ed
uc
at
io
n.
co
m
Output
Date Object
The Date object provides the day, date, and time information.
Syntax: dateObject.method(#)
hi
Example
<SCRIPT language="javascript">
ks
presentYear = year.getFullYear()
.s
a
alert(presentYear);
w
w
</SCRIPT>
www.sakshieducation.com
www.sakshieducation.com
ed
uc
at
io
n.
co
m
Output
String Object
The String object provides methods and properties for string
manipulation and formatting
Syntax: stringName.method(#)
ks
hi
Example
<SCRIPT language="javascript">
var theString = "Hello Sakshi"
.s
a
w
w
</SCRIPT>
www.sakshieducation.com
www.sakshieducation.com
ed
uc
at
io
n.
co
m
Output
<body>
ks
Example1
<html>
hi
.s
a
</body>
w
w
</html>
Output
Before click
www.sakshieducation.com
ed
uc
at
io
n.
co
m
www.sakshieducation.com
w
w
.s
a
ks
hi
After click
www.sakshieducation.com
www.sakshieducation.com
Example2
<html>
<body>
<p onclick="this.style.color='green'">Click me to change color</p>
co
m
</body>
</html>
w
w
.s
a
ks
hi
ed
uc
at
io
n.
Output
Before click
www.sakshieducation.com
www.sakshieducation.com
w
w
.s
a
ks
hi
ed
uc
at
io
n.
co
m
After
click
www.sakshieducation.com