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

  • Home
  • SEARCH
  • 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 7565423
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T14:09:06+00:00 2026-05-30T14:09:06+00:00

From Test.html I include a test.js that runs function d() . This function has

  • 0

From Test.html I include a test.js that runs function d(). This function has a parameter a string that might contain “new line” characters (10 in ASCII), as per example below. However, when I am debugging this function, vars s and data include all characters except the new line, i.e., they contain string “HelloWorld” (length 10) instead of “Hello[charNewLine]World” (length 11).

Is there a way to pass a string with new line characters as parameter to a function in Javascript? Thank you.

Test.html

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=x-user-defined">
<title>JavaScript Scripting</title>
</head>
<body>
<script type="text/javascript" charset="x-user-defined" src="test.js">
</script>
</body>
</html>

test.js

function d(s) 
{
    var data = (s + "").split("");
    var dataLength = data.length;
    var t = [dataLength],n;

    for(n=0;n<dataLength;n++)
    t[n]=data[n].charCodeAt(0);
}
d("Hello\
World");
  • 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-30T14:09:08+00:00Added an answer on May 30, 2026 at 2:09 pm
    d("Hello\
    World");
    

    contains a "line continuation".

    The language specification says

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

    …

    The SV of LineContinuation :: \ LineTerminatorSequence is the empty character sequence.

    which means that it contributes no characters to the value of the string literal.

    To embed a newline in a string, just use \n as in

    d("Hello\nWorld")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I often hear around here from test driven development people that having a function
This is one of the programming questions asked during written test from Microsoft. I
I am skinning a 3rd party app that has no HTML natively. It all
I have an AJAX script that receives a string from a mySQL query returned
I wrote a flex application that get the host string from the browser using
If you want to move your development process from Test-Driven Development to Behavior-Driven Development
What is the best way to deploy a heavily customized SharePoint solution from test
From a question on the Practice C test from GeekInterview, why is the size
If I reference the SnakeYAML jar directly from a test program (see bottom), everything
I need to have a dynamic URL preferably from a Test Class. Can any

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.