Javascript Basics - Supercoders | Web Development and Design | Tutorial for Java, PHP, HTML, Javascript Javascript Basics - Supercoders | Web Development and Design | Tutorial for Java, PHP, HTML, Javascript

Breaking

Post Top Ad

Post Top Ad

Sunday, January 8, 2017

Javascript Basics


Javascript Basics



Javascript is a client side popular language used in many things like in our website, Hybrid Mobile Application, etc.

In Earlier Javascript is used only in websites But now a days javascript is very and used in many devices.

What Javascript Can Do?

Javascript in Web Can Change HTML tags ,CSS Style, HTML Attributes, HTML Contents, HIDE Elements, Show Elements.

Javascript in Mobile Application Can Call Native Java Functions, Swift function , C# functions and Methods of different programing languages.

Where to Put javascript Codes?

Javascript can be Call in web Page by two methods : -

1. By using Internally
Javascript Codes Must be Inside in Script tag

Example :-

<html>
<head>
<!--Adding javascript in our page-->
<script>
alert(“Calling javascript”); //calling alert function
</script>
</head>
<body>
<h2>Javascript Basics</h2>
</body>
</html>

2.By using Externally

Example :-

page.html

<html>
<head>
<!--Adding javascript in our page-->
<script src=”script.js”></script>
</head>
<body>
<h2>Javascript Basics</h2>
</body>
</html>
script.js

alert(“Calling javascript”); //calling alert function


Note :- Javascript is must different from java

Javascript Outputs

JavaScript can display data in different Such Ways :
  • Writing into an alert box, using alert().
  • Writing into the HTML output using document.write().
  • Writing into an HTML element, using innerHTML.
  • Writing into the browser console, using console.log().


Using alert
<html>
<body>
<h2>Javascript basics</h2>

<script>
alert(Hello Js);
</script>

</body>
</html>


Using document.write
<html>
<body>
<h2>Javascript basics</h2>

<script>
document.write(Hello javascript);
</script>

</body>
</html>

Using document.write
<html>
<body>
<h2>Javascript basics</h2>

<script>
document.write(Hello javascript);
</script>

</body>
</html>

Using innerHTML

<html>
<body>

<h2>Javascript basics</h2>

<p id="display"></p>

<script>
document.getElementById("display").innerHTML = hello javascript;

//here document.getElementById is a selector which select the html elements by using id and change the text inside this tag
</script>

</body>
</html>

Using console.log

<html>
<body>

<h2>Javascript basics</h2>

<script>
console.log(hello javascript);

//open your browser console by pressing F12 Key

</script>

<
/body>
<
/html>

Javascript Syntax

Javascript Statements Must be End With (;) Semicolon

Javascript Use var keyword to Store and Declare variable

Javascript Concatinate using +

Example : var a=”hello”+” ”+”Js”

Javascript Comments
//This is single line comments
/*This is Multi Line comments */

Thank You

No comments:

Post a Comment

Post Top Ad