geekskai Logogeekskai
ToolsBlogPricing
Sign in
Sign in
ToolsBlogSign in
Thursday, November 14, 2024|2.145Mins Read

How to Check Whether a Character Is a Double Quote in JavaScript

Authors
  • avatar
    Name
    Geeks Kai
    Twitter
    @KaiGeeks
Discuss on Twitter • View on GitHub

Tags

javascriptcharacterdouble-quoteprogramming-techniques

Previous Article

Crypto Engine.Pro Blog: Your Essential Guide to Crypto

Next Article

How to Make Videos That Drive Sales: Essential Tips for Marketers
← Back to the blog
geekskai Logo
geekskai

Public tools for developers and creators, plus optional Geekskai Audio Toolkit plans. Built with care.

Popular Tools

SoundCloud DownloaderSoundCloud to MP3SoundCloud to WAVSoundCloud PlaylistSoundCloud Artwork
View All Tools

Resources

BlogAbout MePricingTagsProjectsPrivacy PolicyTerms of ServiceRefund Policy

Connect With Us

mailMail
githubGitHub
twitterTwitter
linkedinLinkedin
© 2026 geekskai • All rights reserved

Quick answer: compare the whole value

Use value === '"' when the value must be exactly one ASCII double quote, U+0022. It returns false for an empty string, a longer string, a curly quote or a non-string value. Escaping a quote in JavaScript source does not change the character stored in the resulting string.

function isDoubleQuote(value) {
  return value === '"'
}

function containsDoubleQuote(text) {
  if (typeof text !== "string") {
    throw new TypeError("Expected a string.")
  }
  return text.includes('"')
}

const supportedQuoteCharacters = new Set(['"', "“", "”"])
function isSupportedDoubleQuote(value) {
  return supportedQuoteCharacters.has(value)
}

console.log(isDoubleQuote('"')) // true
console.log(isDoubleQuote('"hello')) // false: longer than one quote
console.log(isDoubleQuote("“")) // false: different code point
console.log(isDoubleQuote(null)) // false: no coercion
console.log(containsDoubleQuote('say "hello"')) // true
console.log(isSupportedDoubleQuote("“")) // true: explicitly allowed

A character, a prefix and a substring are different tests

RequirementCheck for a string input
Exactly one ASCII double quotetext === '"'
First character is a double quotetext.startsWith('"')
A double quote anywheretext.includes('"')
Both a single quote and a double quote occurTwo includes() checks combined with &&
const quotedText = '"hello'
console.log(quotedText.startsWith('"')) // true: starts with a quote
console.log(quotedText.charCodeAt(0) === 34) // true: first UTF-16 code unit is U+0022
console.log(quotedText === '"') // false: the whole string is not one quote

const bothQuoteTypes = "it's a \u0022quote\u0022"
console.log(bothQuoteTypes.includes("'") && bothQuoteTypes.includes('"')) // true
console.log(/["']/.test("|")) // false: two quote characters, not a pipe

charCodeAt(0) === 34 inspects only the first UTF-16 code unit. It does not prove that the entire string has length one. Likewise, /"/.test(text), match(/"/) and indexOf('"') !== -1 detect presence, not exact equality.

Decide whether curly quotes are allowed

ASCII ", left curly “ and right curly ” are distinct characters. The Set-based helper explicitly permits these three and nothing else. It is an application policy, not a claim that all quotation marks in every language are included.

Inside a regular-expression character class, characters are alternatives; || is not a logical OR operator. A class such as /['|" ]/ would also allow a pipe or space. Use /["']/ only when the intended task is presence of either ASCII quote character.

Keep parsing separate

Finding quote characters is not sufficient to parse JSON, CSV, escaped strings or nested language syntax. Use the relevant parser for those tasks. For this character-level question, direct strict equality is the clearest starting point.

References

  • ECMAScript: string inspection methods
  • MDN: String.includes
  • MDN: regular-expression character classes