Math Functions – JavaScript

Table of Contents

Ceil

5

				
					<script> a=4.01; b=Math.ceil(a);
document.write(b);
</script>
				
			

Charat

9

				
					var str = "9971486942";
var charPosition = 9;
if (charPosition >= 0 && charPosition < str.length) {
    var char = str.charAt(charPosition - 1); 
    document.write(char);
} else {
    document.write("Position out of range");
}
				
			

Charcode

A

				
					<script> var res = String.fromCharCode(65);
document.write(String.fromCharCode(65));
document.write("<br>"+res); </script>
				
			

CharCodeAt

65

90

				
					<script> var str="A";
var str1="Z"; document.write(str.charCodeAt(0)+"<br>");
document.write(str1.charCodeAt(0)); 
<!--code of specific character -->
</script>
				
			

Concatenate

sanjayjain

sanjay jain

				
					<script>
var a="sanjay";
var b="jain";
var c=a.concat(b);
document.write(c+"<br>");
var d=a+"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"+b; document.write(d);
</script>
				
			

Floor

4

				
					<script>
    a=4.999999;
    b=Math.floor(a);
    document.write(b);
    </script>
				
			

IndexOf

2

				
					<script> 
var str="aj@ay"; 
document.write(str.indexOf("@")); 
</script>
				
			

LastIndexOf

12

				
					<script>
    var str="sanjay kumar jain";
    document.write(str.lastIndexOf(" "));
    </script>
				
			

length

8

				
					<script>
    var mob="abcdefgh";
    var a=mob.length; document.write(a+"<br>");
    </script>
				
			

Lower case

hello world!

				
					<script>
    var txt="Hello world!";
    document.write(txt.toLowerCase());
    </script>
				
			

Not a Number

plz enter (a-z)

				
					<script>
    var txt=123; 
    if(isNaN(txt)){ document.write("correct");
    }else{ document.write("plz enter(a-z)");
    } </script>
				
			

PI

3.141592653589793

				
					<script>
    c=Math.PI;
    document.write(Math.PI);
    </script>
				
			

Round

4
				
					<script>
    a=4.49999999;
    b=Math.round(a);
    document.write(b);
    </script>
				
			

Upper case

HELLO WORLD!

				
					<script> 
var txt="Hello world!";
document.write(txt.toUpperCase());
</script>
				
			

Take Your Free Live Demo Class Now

You May Also Like

Enter Your DETAILS BELOW

To Get Complete Information or We Will Call You

We Will Send You the Course Fees Details In Below Number

Enter Your DETAILS BELOW

We Will Call Back You Shortly

Enter Your DETAILS BELOW

We Will Call Back You Shortly

Enter Your DETAILS BELOW

Enter Your DETAILS BELOW TO take

free demo class