Css Practical No-5
Css Practical No-5
JavaScript String
The JavaScript string is an object that represents a sequence of characters.
There are 2 ways to create string in JavaScript
1. By string literal
2. By string object (using new keyword)
1) By string literal
The string literal is created using double quotes. The syntax of creating string using string
literal is given
below:
var stringname="string value";
Example:
<!DOCTYPE html>
<html>
<body>
<script>
varstr="This is string literal";
document.write(str);
</script>
</body>
</html>
Example
<!DOCTYPE html>
<html>
<body>
<script>
// Get the character at the 3rd position (index 2) of the string "javascript"
var str = "javascript";
document.write(str.charAt(2)+<br>”); // Output: "v"
Output