button onclick event example javascript

Here is the example of button click Example javascipt

<button onclick="myFun()">Click me</button>

<p id="demo"></p>
<script>
function myFun()
{
document.getElementById("demo").innerHTML="Test";
}
</script>

Javascript function

A JavaScript function is a block of code designed to perform a particular task.
A JavaScript function is executed when "something" calls it

Here is Example Of javascript function
<script>
function myfun(p,p1)
{
return p * p1;
}
document.getElementById("test").innerHTML=myfun(4,1);

</script>

Javascript Objects

JavaScript objects are written with curly braces.Object properties are written as name:value pairs, separated by commas.

Here is Example of object

<p id=""></p>
<script>
var per={name:"bipin",sex:"male",age:"20"}

document.getelementById("test").innerHTML=per.name +""+ per.sex+"";


</script>


javascript array

Javascript array declare in square brackets and array ithem are seperated by commas


Here is Example of array in javascript

<p id="test"> </p>

<script>
var car=["honda","maruti","tata"];
getElementById("test").innerHTML=car[0];

</script>

0utput will get honda..



How can add value to variable

we can use += operater to add a value to varable

For example

<p id="test">  </p>

<script>

var a;

a=10;
a+=10;

document.getElementById("test").innerHTML=a;




</srcipt>

How can concatenate String in javascript

+ operator used for concatenate string in Javascript

We can also use += operator for concatenate string

Example like

var a,b,c;
a="test";
b="test1";
c= a+ " " + b;



what is Value = undefined in javascript

a variable declare a value not defind that is called undefind

For Example
<p id="test">
<script>
Var a;

document.getElementById("test").innerHTML=a;

</script>

Javascript Comment


There are two type comment in javascipt 

one is single line comment

//
other one is multi line comment

/*

*/

How Can Assigning value in javascript

How Can Assigning value in javascript


We can assign value in javascript in = sign


Here is the Example of code

<p id="test"></p>

<script>
var a,b
a=10;
b=10
document.getElementById("test").innerHML=a+b;
</script>

Output will be 20 ...

Simple Example of Javascript

<!DOCTYPE html>
<html>
<body>

<h1>Simple Example of javascript</h1>

<p id="demo">Test</p>

<button type="button" onclick='document.getElementById("demo").innerHTML = "Hello JavaScript!"'>Click Me!</button>

</body>
</html>

it will display out

Simple Example of javascript

Hello JavaScript!


What is javascript

JavaScript is programming language of html and Web. JavaScript  is dynamic and high level and interpreted programming language also it easy to study for learners