It is not necessary to define the data type when initializing the variables in Javascript. It automatically gets the data type of the variable according to the value stored in the variable. That is calling Dynamic Type Variables. Therefore Same variable can be used to store following kind of data in JavaScript
1. String
A set of characters can be stored by putting between the Double Quotes or Single Quote
Syntax:
var <variable name> = '<Value>' OR
var <variable name> = "<Value>"
Ex:
var student = "John"; // OR
var student = 'John';
var Relationship= "John's car"; // Can put single Quotes within Double Quotes
var car = 'John has "Toyota" car'; // Can put Double Quotes within Single Quotes
2. Number
Numbers in the can be written with or without decimal places.
var no1 = 50;
var no1 = 53.25;
This blog supports beginners to get deep knowledge about programming in HTML, CSS, JavaScript, php, asp and other Web technologies and VB, VB.net, Java,step by step from the beginning. All the programming Concepts discuss with simple examples for the readability. Try out daily uploaded lessons to be a Programmer.
Showing posts with label 3. JavaScript. Show all posts
Showing posts with label 3. JavaScript. Show all posts
Javascript - Comments
We are using comments to make Javascript more readable and comments are not executed by JavaScript. That can be used to explain the coding. In JavaScript, there are two types of comments can be used,
01. Single Line Comments
Single Line Comments begins with 02 forward slashes and there is no ending, its
applicable to the whole line which it puts.
Syntax:
// <Comment>
Ex:
// This is a single line Comment
var no = 0; // This is Number type variable
02. Multi Line Comments
Multi Line Comments begins with a /* and ends with */.
Syntax:
/* <Comment> */
Ex:
/* This is a Multi line Comment
Purpose of this comment is explain
the code with more than one line */
Web Programing for Beginners
Is this blog helpful for you? Can you recommend for someone?
I much appreciate your kind suggestions and comment to improve the contents & writing method of this blog. Because you are the actual reader of this site and strive to sharpen your web programming knowledge.
You may knowing further more about the discussed topics or have articles, links related to the topics please put it in your comment. Those comments more helpful others as well as me.
--
Best regards,
Priyal
How to use External JavaScript
JavaScript can also be put as an external files like as CSS files. JavaScript files saved with the extention of ".js".
When using an External script, you can't use the <script>...</script> tags. Use src attribute of the <Script> tag to specify the .js external javascriptfile.
<html>
<head>
<script type = "text/javascript" src = "test.js" > </script>
</head>
</html>
When using an External script, you can't use the <script>...</script> tags. Use src attribute of the <Script> tag to specify the .js external javascriptfile.
<html>
<head>
<script type = "text/javascript" src = "test.js" > </script>
</head>
</html>
Javascript - How to write 1st Javascript
This example displays how to use javascript to write something in the HTML Document
<html>
<body>
<script type = "text/javascript">
document.write ("Hello!.. This is my 1st Javascript program");
</script>
</body>
</html>
Following example displays how to use HTML elements within the javascript
<html>
<body>
<script type = "text/javascript">
document.write ("<h2>Hello!.. This is my 1st Javascript program</h2>");
</script>
</body>
</html>
<html>
<body>
<script type = "text/javascript">
document.write ("Hello!.. This is my 1st Javascript program");
</script>
</body>
</html>
Following example displays how to use HTML elements within the javascript
<html>
<body>
<script type = "text/javascript">
document.write ("<h2>Hello!.. This is my 1st Javascript program</h2>");
</script>
</body>
</html>
How to Put JavaScript into HTML Document
Where to put javaScript
This is the syntax of javascript using in HTML Documents
<html>
<head>
<title>JavaScript implement in HTML Doc</title>
<script type = "text/javascript" >
............
</script>
</head>
<body>
<script type = "text/javascript" >
............
</script>
</body>
</html>
- Within the Header Segment
- Within the Body Segment
This is the syntax of javascript using in HTML Documents
<html>
<head>
<title>JavaScript implement in HTML Doc</title>
<script type = "text/javascript" >
............
</script>
</head>
<body>
<script type = "text/javascript" >
............
</script>
</body>
</html>
HTML with Javascript
Javascript is a client-side scripting language and can be used with HTML.
alert
Web browser displays Message Window with the event of calling javascript.
<a href = "http://programmingforbeginers.blogspot.com" onclick = "alert('This is a Javascript message')">Programming Languages for Beginners</a>
alert
Web browser displays Message Window with the event of calling javascript.
<a href = "http://programmingforbeginers.blogspot.com" onclick = "alert('This is a Javascript message')">Programming Languages for Beginners</a>
JavaScript Basic
- We use <script> tag to insert javascript to a HTML document. Inside the script tag we use Type attribute to define the scripting language. It is optional to use the attribute of Language to define the script language.
- JavaScript can be put under the header segment or body segment. Something needed to do before loading the page, you can define under header segment.Syntax:<script language = "javascript" type = "text/javascript" >------</script>
- Opening tag of <script language = "javascript" type = "text/javascript" > and the closing tag of </script> tells where the JavaScript starts and ends.
- To write some output to the HTML body we use standard JavaScript command of document.write()
Ex:<script language = "javascript" type = "text/javascript" >document.write("Hello!.. This is my 1st JavaScript Program");</script>
JavaScript
What is Java Script?
- Introduced in 1996 by the Netscape team and release with Netscape 2.0
- Javascript was design to add interactivity to HTML documents
- Javascript is a scripting language specially a client side scripting language
- Javascript is usually embedded directly into HTML documents
- Javascript is a dynamic type programming Language
- Javascript supports all the browsers namely Internet Explorer, Mozilla Firefox, Google Chrome, Opera & Safari.
- Javascript can be used to form verification
- Javascript can be used to Basic document intelligence that can embed a base level of intelligence to the document by linking elements to script via events
- Javascript can be used to document animation and automation
- Everyone can be used to react to events
- The standard was approved as an International ISO (ISO/IEC 16262) standard in 1998.
Syntax:
<script language = "javascript" type = "text/javascript"
------
</script>
* Some earlier browsers are not supporting for Javascript & display the code as body content. To prevent that, include javascript inside the HTML comment tag. Javascript supporting browsers interpret following & others hiding the code.
Ex:
<script language = "javascript" type = "text/javascript">
* Some earlier browsers are not supporting for Javascript & display the code as body content. To prevent that, include javascript inside the HTML comment tag. Javascript supporting browsers interpret following & others hiding the code.
Ex:
<script language = "javascript" type = "text/javascript">
<!--
document.write("This phrase inside the HTML Comment");
-->
document.write("This phrase inside the HTML Comment");
-->
</script>
Subscribe to:
Posts (Atom)