Create a string type variable with either double quotes (") or single quotes (') in JavaScript

Description

The following code shows how to create a string type variable with either double quotes (") or single quotes (').

Example


<!--from w  w w.  jav a 2s .  com-->
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
var firstName = "first";
var lastName = 'last';
document.writeln(firstName);
document.writeln(lastName);
</script>
</head>
<body>

</body>
</html>

Click to view the demo

The code above generates the following result.

Create a string type variable with either double quotes (") or single quotes (