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 8945225
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:12:00+00:00 2026-06-15T12:12:00+00:00

Consider this string: var s = A\0Z; Its length is 3, as given by

  • 0

Consider this string:

var s = "A\0Z";

Its length is 3, as given by s.length. Using console.log you can see the string isn’t cut and that s[1] is "" and s.charCodeAt(1) is 0.

When you alert it in Firefox, you see AZ. When you alert it in Chrome/Linux using alert(s), the \0 terminates the string and you see A.

My question is: what should browsers and Javascript engines do? Is Chrome buggy here? Is there a document defining what should happen?

As this is a question about standard, a reference is needed.

  • 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-06-15T12:12:01+00:00Added an answer on June 15, 2026 at 12:12 pm

    What the browser should do is keep track of the string and its length separately since there are no null terminators present in the standard. (A string is just an object with a length).

    What Chrome seems to do (I am taking your word for this) is use the standard C string functions which terminate at a \0. To answer one of your questions: Yes this to me constitutes a bug in Chrome’s handling of the alert() function.

    Formally the spec says:

    A string literal is zero or more characters enclosed in single or double quotes. Each character may be represented by an escape sequence. All characters may appear literally in a string literal except for the closing quote character, backslash, carriage return, line separator, paragraph separator, and line feed. Any character may appear in the form of an escape sequence.

    Also:

    A string literal stands for a value of the String type. The String value (SV) of the literal is described in terms of character values (CV) contributed by the various parts of the string literal.

    And regarding the NUL byte:

    The CV [Character Value] of EscapeSequence :: 0 [lookahead ∉ DecimalDigit] is a <NUL> character (Unicode value 0000).

    Therefore, a NUL byte should simply be “yet another character value” and have no special meaning, as opposed to other languages where it might end a SV (String value).

    For Reference of (valid) “String Single Character Escape Sequences” have a look at the ECMAScript Language spec section 7.8.4. There is a table at the end of the paragraph listing the aforementioned escape sequences.

    What someone aiming to write a Javascript engine could probably learn from this: Don’t use C/C++ string functions. 🙂

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

Sidebar

Related Questions

If we consider a std::string implementation that uses reference counting, consider this scenario: int
Consider a string that looks like this: RR1 S5 C92 This a rural route
Consider this code snippet: class Program { static void Main(string[] args) { Console.WriteLine(Test().ToString()); }
Consider this: my $var = ${SOME_VAR} my $string In this text ${SOME_VAR} will be
Consider this code: static void Main(string[] args) { var persons = new List<Person> {
Consider this javascript code: var s = Some string; s = More string; Will
Consider this code : TForm3 = class(TForm) public class procedure GetAConn(var res:String); overload; class
Consider this string, var string = "sometext/#a=some_text/#b=25/moretext"; What I would like to do is
Consider this simple program: private static void Main(string[] args) { var directoryName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
Consider this array string[] presidents = { Adams, Arthur, Buchanan, Bush, Carter, Cleveland, Clinton,

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.