We can check both the variables using typeof and see what is returned in the console. In JavaScript, it doesn't really matter whether the string has been declared using single quotes or double-quotes. Unlike some other c-type languages like PHP which interpret strings differently based on whether they are declared using single quotes or double quotes, JavaScript makes no differentiation. The only difference that we have here is that the firstName has been declared using double quotes and the lastName has been declared using single quotes. Let lastName = "Doe" // using single quotes let firstName = "John" // using double quotes Let's start by defining two variables that use two different syntaxes. So stick around till the end of the article to get a complete understanding of the string literal syntax as well as the traditional syntax of declaring and working with JavaScript Strings.īefore ES6, JavaScript had two syntaxes for declaring strings, which are very much valid as of now. We will also look at how you can create strings using template literals in JavaScript. We will create strings in JavaScript using the traditional syntax of single quotes and double-quotes. This is a quick introduction to string data types in JavaScript. Template literals or string literals are a new syntax in ES6.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |