0% found this document useful (0 votes)
17 views

Javascript 1

The document discusses computer programming and scripting languages. It explains that programming involves writing code in a language that computers can understand to perform tasks. Scripting languages do not require compilation and are interpreted. Examples of server-side scripting languages include Perl, PHP and Python, while JavaScript is a common client-side scripting language. The document also covers web servers, their role in delivering web pages via HTTP, and examples like Apache and IIS.

Uploaded by

itikhed971
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Javascript 1

The document discusses computer programming and scripting languages. It explains that programming involves writing code in a language that computers can understand to perform tasks. Scripting languages do not require compilation and are interpreted. Examples of server-side scripting languages include Perl, PHP and Python, while JavaScript is a common client-side scripting language. The document also covers web servers, their role in delivering web pages via HTTP, and examples like Apache and IIS.

Uploaded by

itikhed971
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

•Computer programming is the process of writing instructions that get

executed by computers. The instructions, also known as code, are written


in a programming language which the computer can understand and use
to perform a task or solve a problem.
•A script or scripting language is a computer language with a series of
commands within a file that is capable of being executed without being
compiled.
• Good examples of server-side scripting languages include Perl, PHP,
and Python.
•The best example of a client side scripting language is JavaScript.
•All scripting languages are programming languages.
•Scripting language do not require the compilation step and are rather
interpreted
•A server is a computer that provides data to other computers.

Request a Page
Your local Server
computer with computer with
web browser web server
software software
Sends Requested
Page

•The most common use of web servers is to host websites. but there
exists other web servers also such as gaming, storage, FTP, email etc. A
web server can host hundreds of web sites.
•The primary job of a web server is to deliver web pages to clients.
•The communication between the client node and server node takes place using the
Hypertext Transfer Protocol (HTTP).
• The delivered web pages include images, style sheets and scripts in addition to text
content
•A web server is a physical computer or piece of hardware that delivers content or
services to end users over the Internet.
•Web server is a computer where the web content is stored.
•Types \examples of web servers
1.Apache web server
•One of the most popular and open source web server in the world developed
by the Apache Software Foundation. Runs on all operating systems
2.IIS web server
IIS stands for Internet information services.
•It is developed by Microsoft but it is not open source.
•it works with all the windows operating system platforms
•JavaScript is a very powerful client-side scripting
language.
•Used mainly for enhancing the interaction of a user with
the webpage \to make webpage more interactive.
•Apart from client side validation JavaScript is also being
used widely in game development and Mobile application
development.
•JavaScript was developed by Brendan Eich in 1995.
•Initially called Live Script and was later renamed
JavaScript.
1.Client side validation
2.Manipulating HTML Pages -
3.User Notifications\ pop-up windows and dialog boxes
4.Back-end Data Loading -
5.Presentations
6. Web Applications
7. Games
8.Smartwatch Apps
9. Mobile Apps
10.For making server applications
11.Dynamic drop-down menu
12.Displaying date and time
13.Displaying clocks etc.
•JavaScript can be implemented using JavaScript statements
that are placed within the <script>... </script> tags in a web
page.
•It is recommended that you should keep it within
the<head>tags.
• A simple syntax of your JavaScript will appear as follows.
<script ...>
JavaScript code
</script>
•The <script> tag alerts the browser program to start
interpreting all the text between these tags as a script
•Language: This attribute specifies what scripting language you are
using. Typically, its value will be JavaScript.
•Type: This attribute is what is now recommended to indicate the
scripting language in use and its value should be set to
“text/javascript".
•Src: Specifies the location of an external scripting file. The .js
extension is normally used for JavaScript code files.
So your JavaScript syntax will look as follows.
<script language="javascript" type="text/javascript">
JavaScript code
</script>
Note- The language and type attributes are now optional. we
can execute javascript code without using this attributes also.
In this example, JavaScript is embedded within the header. As soon as the page
is loaded this code is executed.
 <html>

 <head>

 <title>JavaScript Example</title>

 <script>

 document. write("Hello World!");

 </script>

 </head>

 <body>The body</body>

 </html>

we call a function document. write which writes a string into our


HTML document. The Document write method displays the text.
1. Between head tag\Script in <head>...</head>
section.

2. Between the body tag\Script in <body>...</body>


section.

3. In .js file \Script in an external file and then


include in <head>...</head> section.
<html>
<head>
<title>js program in body section<\title>
</head>
<body>
<script type="text/javascript">
document.write("Hello World")
</script>
<p>This is web page body </p>
</body>
</html>
 We can create external javascript file once and embed\add it in many
html pages.
 It provides code reusability because single JavaScript file can be used
several times.
 The script tag provides a mechanism to allow you to store JavaScript
in an external file and then include it into your HTML files.
 An External javascript file must be saved with .js extension.
 To use JavaScript from an external file source, you need to write all
your JavaScript source code in a simple text file with the extension
".js" and then include that file in head section of html page.
 For example, you can keep the following content in sample.js file and
then
 you can use sayHello function in your HTML file after including the filename.js file .
•Here,Sample.js will include
function sayHello()
{
alert("Hello World")
}
Here is an example to show how you can include an external JavaScript file in your
HTML code using script tag and its src attribute.
<html>
<head>
<script type="text/javascript" src="sample.js" ></script>
</head>
<body>
<script>
sayHello()
</script>
</body>
</html>
 Comments are used to give more information about the code to the
end user.
 Comments are not the part of the code so it is ignored by the
JavaScript engine.
 It makes code easy to understand
 Types of JavaScript comments
1. Single-line Comment
2. Multi-line Comment
Ex 1.
<script>
//it is single line comment
document. write(“Hello”);
</script>
Ex 2.
<script>
Var a=10;
Var b=20;
Var c=a + b //it adds values of a and b variable
</script>
<script>
/*variable declaration in
JavaScript*/
Var a;
Var b;
</script>
 JavaScript variables are containers for storing data
values.
 You can place data into these containers and then refer
to the data simply by naming the container.
 Before you using a variable in a JavaScript program,
you must declare it.
 Variables are declared with the var keyword .
 A JavaScript variable is simply a name of storage
location used to refer a value.
 Variables are used to hold data.
• Names can contain letters, digits, underscores, and
dollar signs.
• Names must begin with a letter , $(dollar sign) or
_(underscore)
• Names are case sensitive (a and A are different variables)
•Variables can not start with a number, After first letter we
can use digit for example value1
• Reserved words like JavaScript keywords cannot be
used as names
var age=12 Variable
Keyword Value
Variable
name
In following example 1,
 a, b, and c, are variables:
 Example 1
var a = 12;
var b = 10;
var c = a + b;
• a stores the value 12
• b stores the value 10
• c stores the value 22
 .
 Correct JavaScript  Incorrect
variable names JavaScript variable
var x names
var _v1 var 123
var $abc var *a
var My_name var 1sum
var name1 var first name
var firstName
<script>
Variable
var a ,b, c; Declaration

a=10; Variable
b=20; Initialization
/*variable c is used to store the result of addition of a and
b*/
c= a+b;

document.write(c);
</script>
Constants in JavaScript
 constants are special kind of variable used to
store value that can be e never change during
the execution of program
 const keyword is used to to declare a constant
 Syntax-
const nameofconstant =value ;
 Example
 const SSCMarks=89;
 Data type are used to specify that what kind of
data is to Store in the variable.

You might also like