0% found this document useful (0 votes)
74 views

CharCodeAt - fromCharCode and BgColor

The document discusses JavaScript string methods charCodeAt() and fromCharCode(). charCodeAt() returns the Unicode of the character at a given index. fromCharCode() converts Unicode values to string characters. It also covers the document.bgColor property, which specifies the background color of an HTML document as a hexadecimal or standard color name string.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
74 views

CharCodeAt - fromCharCode and BgColor

The document discusses JavaScript string methods charCodeAt() and fromCharCode(). charCodeAt() returns the Unicode of the character at a given index. fromCharCode() converts Unicode values to string characters. It also covers the document.bgColor property, which specifies the background color of an HTML document as a hexadecimal or standard color name string.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

CSS[22519] MR.SWAMI R.S.

{MOBILE NO:-+91-8275265361]

JavaScript String - charCodeAt() Method

The JavaScript CharCodeAt function is used to return the Unicode of the Character at specified
index position.

Syntax
Use the following syntax to find the character code at a particular index.
string.charCodeAt(index);

Argument Details
index − An integer between 0 and 1 less than the length of the string; if unspecified, defaults to
0.
<script>
// JavaScript to illustrate charCodeAt() function

function func() {
var str = 'Omsairam';

// Finding the code of the character at


// given index
var value = str.charCodeAt(4);
document.write(value);
}

func();
</script>

OR

<html>
<head>
<title>JavaScript String charCodeAt() Method</title>
</head>

<body>
<script type = "text/javascript">
var str = new String( "This is string" );
document.write("str.charCodeAt(0) is:" +
str.charCodeAt(0));
document.write("<br />str.charCodeAt(1) is:" +
str.charCodeAt(1));
document.write("<br />str.charCodeAt(2) is:" +
str.charCodeAt(2));

VAPM,Almala-Inst.Code-1095
CSS[22519] MR.SWAMI R.S.{MOBILE NO:-+91-8275265361]

document.write("<br />str.charCodeAt(3) is:" +


str.charCodeAt(3));
document.write("<br />str.charCodeAt(4) is:" +
str.charCodeAt(4));
document.write("<br />str.charCodeAt(5) is:" +
str.charCodeAt(5));
</script>
</body>
</html>

ASCII Hex Symbol ASCII Hex Symbol ASCII Hex Symbol ASCII Hex Symbol

64 40 @ 80 50 P 96 60 ` 112 70 p
65 41 A 81 51 Q 97 61 a 113 71 q
66 42 B 82 52 R 98 62 b 114 72 r
67 43 C 83 53 S 99 63 c 115 73 s
68 44 D 84 54 T 100 64 d 116 74 t
69 45 E 85 55 U 101 65 e 117 75 u
70 46 F 86 56 V 102 66 f 118 76 v
71 47 G 87 57 W 103 67 g 119 77 w
72 48 H 88 58 X 104 68 h 120 78 x
73 49 I 89 59 Y 105 69 i 121 79 y
74 4A J 90 5A Z 106 6A j 122 7A z
75 4B K 91 5B [ 107 6B k 123 7B {
76 4C L 92 5C \ 108 6C l 124 7C |
77 4D M 93 5D ] 109 6D m 125 7D }
78 4E N 94 5E ^ 110 6E n 126 7E ~
79 4F O 95 5F _ 111 6F o 127 7F •

JavaScript FromCharCode()
The JavaScript FromCharCode function is one of the JavaScript String Function which is
used to convert the Unicode values to string values (based on ASCII Table).

JavaScript FromCharCode Syntax

The basic syntax of the FromCharCode function is as shown below:

String.fromCharCode(ASCII_Value)

NOTE: The FromCharCode() function is a static function of string objects so, we have to
use String Object while calling this function. For example, String.fromCharCode(109)

VAPM,Almala-Inst.Code-1095
CSS[22519] MR.SWAMI R.S.{MOBILE NO:-+91-8275265361]

Arguments
The function takes the UTF-16 Unicode sequences as its argument. The number of
arguments to this function depends upon the number of characters to be joined as a string.
The range of the numbers is between 0 and 65535

Return value
The return value of this function is a string containing the characters whose UTF-16 codes
were passed to the function as arguments.

Example 1:

<script>
// JavaScript to illustrate fromCharCode() function
function func() {

// UTF-16 codes to be converted into characters


var str = String.fromCharCode(65, 66, 67);
document.write(str);
}

func();
</script>

Document.bgColor()
The bgColor property specifies the background color of HTML document.
The color is expressed as a string in hexadecimal digits or as one of the JavaScript standard
color names.
Syntax

document.bgColor

The hexadecimal form is made up of six digits that follow the pattern "RRGGBB."
The color of the background can also be set with bgcolor attribute of the tag.

<HTML>
<head>
<title>this is a title</title>
</head>
<BODY bgcolor="beige" text= "black">

VAPM,Almala-Inst.Code-1095
CSS[22519] MR.SWAMI R.S.{MOBILE NO:-+91-8275265361]

<SCRIPT>

document.write("The background color is "+document.bgColor+"<BR>");

</SCRIPT>

</BODY>

</HTML>

VAPM,Almala-Inst.Code-1095

You might also like