Insertion of javascript in html,comments in javascript , function of javascript, javascript functions



Comments in javascript

 

Comments are non-executable statement inn program .comments are used to provide information or explanation about programming construct .statement added in comments are ignored by javascript . it supports two types of comments.

1.single line comment  (//…….):

Single line comment begins with   //.

The javascript ignores everything from // to the end of the line .

2.multiple comments :

Multiple comments are used to comment on more then one line .

It starts with /* and ends with */.

 

Commonly used built-in function in javascript

 

Function is used to perform repetitive tasks whenever required . it is reusable code-block  that will be executed when it is called.

 

·         parseInt() :this function is used to parse a string and convert it into a number.

·         parseFloat(): this function is used to parse a string  and convert it into floating point representation.

·         Alert(): this function displays alert popup box with  ok button . this is also called as a message box.

·         Prompt():this function is used  when you want to input value from user at time of program execution . it displays  ok and cancel buttons. ok button returns  input value,cancle button returns null value.

·         Confirm():this function displays confirmation message box with ok and cancel button . ok button returns ‘true’ and cancel buttons returns ‘false’.

·         To lowercase (): this string functions used to convert the given string into lower case alphabets .

·         To uppercase():this string functions used to convert the given string into upper case alphabets .

·         Is NaN(): it returns ‘true ‘is given value is not a number .

·         It returns’ false’ if given value is number.

 

 

 

Example program is as follows

Input:-

 

<!doctype html>

<html>

<head>

<title>area of circle</title>

</head>

<body bgcolor=gold>

<h1>program to calculate area of circle</h1>

<script language="javascript">

var r ,area;

r=prompt("enter the radius of circle");

area=3.14*r*r;

document.write("<h1>you entered radius value:</h1>"+r);

document.write("<h1>area of circle:</h1>"+area);

</script>

</body>

</html>

 

Output:-

 









Comments