Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 808285
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T00:32:17+00:00 2026-05-15T00:32:17+00:00

Possible Duplicates: single quotes versus double quotes in js When to Use Double or

  • 0

Possible Duplicates:
single quotes versus double quotes in js
When to Use Double or Single Quotes in JavaScript

What is the difference (if any) between the javascript strings defined below?

var str1 = "Somestring";

var str2 = 'Somestring';

“” and ” mean two very different things to me predominantly writing code in C++ 🙂

EDIT: If there is no difference why are there two ways of achieving the same thing and which is considered better practice to use and why. Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T00:32:17+00:00Added an answer on May 15, 2026 at 12:32 am

    Javascript treats single and double quotes as string delimiters.

    If you use single quotes, you can use double quotes inside the string without escaping them.

    If you use double quotes, you can use single quotes inside the string without escaping them.

    Both examples evaluate to the same thing.

    alert(str1 == str2); // true
    alert(str1 === str2); // true
    

    Why two ways? Due to the way javascript allows you to mix the two, you can write html attributes out without messy escapes:

    var htmlString1 = "<a href='#'>link</a>";
    var htmlString2 = '<a href="#">link</a>';
    

    As for best practice, there is no convention. Use what feels best.

    Personally, I like making sure the Javascript I emit matches the HTML (if I double quote attributes, I will delimit JS string with a ', so emitted attributes will use ").

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicates: What is the correct way to create a single instance application? Prevent
Possible Duplicates: What is the correct way to create a single instance application? What
Possible Duplicate: Can I protect against SQL Injection by escaping single-quote and surrounding user
Possible Duplicates: Favourite command line trick useful linux commands for programmers? What is your
Possible Duplicates: Multiple IE instances on one machine. Running IE6, IE7, and IE8 on
Possible Duplicates: Ruby/Ruby on Rails ampersand colon shortcut What does map(&:name) mean in Ruby?
Possible Duplicates: Is it possible to decrypt md5 hashes? Is it possible to reverse
Is it possible to compare whole memory regions in a single processor cycle? More
Is it possible to nest simple programs within a Google Sheets, similar to how

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.