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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:05:09+00:00 2026-05-27T04:05:09+00:00

I’m following a node.js tutorial from a book called Node Web Developments. Problem: In

  • 0

I’m following a node.js tutorial from a book called Node Web Developments.

Problem: In one part of the code, an array [] containing HTML code is passed from mult-node.js into the required function htutil.page() as the 3rd argument, and the 2 values returned by exports.navbar() and exports.page() in htutil.js but I cannot figure out why it must be an array and not a long string? I don’t see any code in htutil.page() that extracts the array into a long string where it will be displayed on a HTML page.

htutil.js

var url = require('url');

exports.loadParams = function(req, res, next) {
    req.requrl = url.parse(req.url, true);
    req.a = (req.requrl.query.a && !isNaN(req.requrl.query.a))
        ? new Number(req.requrl.query.a)
        : NaN;
    req.b = (req.requrl.query.b && !isNaN(req.requrl.query.b))
        ? new Number(req.requrl.query.b)
        : NaN;
        if(next) next();
}

exports.navbar = function() {
    return ["<div class='navbar'>",
            "<p><a href='/'>Home</a></p>",
            "<p><a href='/mult'>Multiplication</a></p>",
            "<p><a href='/square'>Square's</a></p>",
            "<p><a href='/factorial'>Factorial's</a></p>",
            "<p><a href='/fibonacci'>Fibonancci's</a></p>".
            "</div>"].join('\n');
}

exports.page = function(title, navbar, content) {
    return ["<html><head><title>{title}</title></head>",
            "<body><h1>{title}</h1>",
            "<table><tr>",
            "<td>{navbar}</td><td>{content}</td>",
            "</tr></table></body></html>"].join('\n');
            .replace("{title}", title, "g")
            .replace("{navbar}", navbar, "g")
            .replace("{content}", content, "g");
}

mult-node.js

var htutil = require('./htutil');
exports.get = function(req, res) {
    res.writeHead('200', {'Content-Type': 'text/html'});
    var result = req.a * req.b;
    res.end(
        // THIS IS THE FUNCTION WHERE THE ARRAY OF HTML CODE IS PASSED INTO
        htutil.page('Multiplication', htutil.navbar(), [
            (!isNaN(req.a) && !isNaN(req.b) ?
                ("<p class='result'>{a} * {b} = {result}</p>"
                .replace('{a}', req.a)
                .replace('{b}', req.b)
                .replace('{result}', req.a * req.b))
                : ""),
            "<p>Enter numbers to multiply</p>",
            "<form name='mult' action='/mult' method='get'>",
            "A: <input type='text' name='a' /><br>",
            "B: <input type='text' name='b' />",
            "<input type='submit' value='Submit' />",
            "</form>"
            ].join('\n'))
        );
}
  • 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-27T04:05:10+00:00Added an answer on May 27, 2026 at 4:05 am

    From what I can see it’s not passing an array – it’s joining it into a string before passing it in.

    The reason for this is that string joining is (at least supposedly) more efficient than repeated concatenation, this of course depends on the implementation of join, but I’d imagine most implementations optimize it. JavaScript doesn’t have a StringBuffer or a StringBuilder type, so joining an array is the closest thing you get.

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

Sidebar

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am currently running into a problem where an element is coming back from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a text area in my form which accepts all possible characters from

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.