Wednesday, 8 November 2017

How Can String Datatype Executed in Javascript

JavaScript string data type represent textual data surrounding to single / double quotes. Each character is represented as an element that occupies the position of that string.

Example: Simple Code for String Datatype
<! DOCTYPE html>
<html>
<body>
<p id="string"></p>
<script>
var carName1 = "Etios";
var carName2 = 'RangeRover';
var answer1 = "It's alright";
var answer2 = "My self 'Matt Henry'";
var answer3 = 'He is called "Robert"';
document.getElementById("string").innerHTML =
carName1 + "<br>" +
carName2 + "<br>" +
answer1 + "<br>" +
answer2 + "<br>" +
answer3;
</script>
</body>
</html>

E.g. Description

Whatever quote you use to represent the string, but you should take care that quote can't repeat in string statement.
Unlike in languages like C, JavaScript strings are immutable. This means that once a string is created, it is not possible to modify it. However, it is still possible to create another string based on an operation on the original string.
Use strings for textual data. When representing complex data, parse strings and use the appropriate abstraction.
Above example describes you to execute the string datatype using the keyword called "var", assigned the function class names as a car with respective to the functioning of that.The getElementById() method returns the element that has the ID attribute with the specified value. We assigned the content in single and double quotes which we wanted to display on the output screen.

READ MORE

No comments:

Post a Comment