Job Interview Questions

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Chu

    #1

    Job Interview Questions

    Recently in a job interview I was asked the following questions. I was
    able to answer the first one, but the 2nd one still baffles me. I'm
    curious if anyone can provide a little insite:

    1) What two chars have to be escaped when performing a
    document.write( )?

    I answered that quotes, both single and double need to be escaped when
    they are supposed to be part of the output of a document.write
    statement.

    He seemed happy with that response.

    2) What is the main thing that has to be done when performing a
    document.write( ) in a script block?

    I had no clue. The question seems pretty vague... I couldn't and still
    can't think of what "has" to be done, besides the obvious of including
    it inside a <script> tag, or adding content to what will be outputted
    in the document.write.

    Any ideas?

  • Jim Ley

    #2
    Re: Job Interview Questions

    On 19 Jun 2005 14:16:43 -0700, "Chu" <ryan@thescottc lan.net> wrote:
    [color=blue]
    >Recently in a job interview I was asked the following questions. I was
    >able to answer the first one, but the 2nd one still baffles me. I'm
    >curious if anyone can provide a little insite:
    >
    >1) What two chars have to be escaped when performing a
    >document.write ()?
    >
    >I answered that quotes, both single and double need to be escaped when
    >they are supposed to be part of the output of a document.write
    >statement.[/color]

    There's lots of others too, newlines and other newline like things
    from unicode for example, others depending on if the document.write is
    inside an XML org SGML document, but that's probably what the
    incompetent test setter was wanting, javascript tests are almost
    universally appalling.
    [color=blue]
    >2) What is the main thing that has to be done when performing a
    >document.write () in a script block?[/color]

    nothing, it's a gibberish question, the man is either completely
    clueless, or trying to throw you to see your reaction.

    Jim.

    Comment

    • Kristian Thy

      #3
      Re: Job Interview Questions

      Quoth Chu:[color=blue]
      > 2) What is the main thing that has to be done when performing a
      > document.write( ) in a script block?[/color]

      Flush the buffer, of course.

      --
      \\kristian

      Comment

      • Chu

        #4
        Re: Job Interview Questions

        Flush the buffer??? I would thing that's all done automatically.. .
        granted, maybe you are just messing around as the question itself has
        no real answer?

        Comment

        • Jim Ley

          #5
          Re: Job Interview Questions

          On 19 Jun 2005 21:39:04 GMT, Kristian Thy <thy@itu.dk> wrote:
          [color=blue]
          >Quoth Chu:[color=green]
          >> 2) What is the main thing that has to be done when performing a
          >> document.write( ) in a script block?[/color]
          >
          >Flush the buffer, of course.[/color]

          And how do you do that exactly?

          Jim.

          Comment

          • Kristian Thy

            #6
            Re: Job Interview Questions

            Quoth Jim Ley:[color=blue]
            > On 19 Jun 2005 21:39:04 GMT, Kristian Thy <thy@itu.dk> wrote:
            >[color=green]
            >>Quoth Chu:[color=darkred]
            >>> 2) What is the main thing that has to be done when performing a
            >>> document.write( ) in a script block?[/color]
            >>
            >>Flush the buffer, of course.[/color]
            >
            > And how do you do that exactly?[/color]

            You start by adjusting your sarcasmometer ...

            --
            \\kristian

            Comment

            • Lasse Reichstein Nielsen

              #7
              Re: Job Interview Questions

              "Chu" <ryan@thescottc lan.net> writes:
              [color=blue]
              > Recently in a job interview I was asked the following questions.[/color]

              That happens a lot these days, it seems.
              [color=blue]
              > 1) What two chars have to be escaped when performing a
              > document.write( )?[/color]

              My immediate response would have been "what do you mean?"
              [color=blue]
              > I answered that quotes, both single and double need to be escaped when
              > they are supposed to be part of the output of a document.write
              > statement.[/color]

              Only one of them, and they need to be escaped inside any string
              delimited by the same kind of quote.

              I would say "<" and "&", if they are to be put into HTML verbatim.
              [color=blue]
              > He seemed happy with that response.[/color]

              It's one way to understand a vague question :)
              [color=blue]
              > 2) What is the main thing that has to be done when performing a
              > document.write( ) in a script block?[/color]

              Call "document.write "? Or my next response: "What *are* you talking
              about?!?".
              [color=blue]
              > I had no clue. The question seems pretty vague...[/color]

              That's an understatement :)

              Going speculative (they might like that), I'd say that since he
              explicitly mentions a script block (the two other options being
              intrinsic event handlers and external script files, and I wouldn't
              document.write inside an intrinisic event handler), it would have to
              be the one thing that differs between scripts embedded in HTML and
              scripts in external files: The need to escape the ETAGO token
              ("</" -> "<\/").

              /L
              --
              Lasse Reichstein Nielsen - lrn@hotpop.com
              DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
              'Faith without judgement merely degrades the spirit divine.'

              Comment

              • Ivo

                #8
                Re: Job Interview Questions

                "Chu" <ryan@thescottc lan.net> wrote[color=blue]
                > Recently in a job interview I was asked the following questions. I was
                > able to answer the first one, but the 2nd one still baffles me. I'm
                > curious if anyone can provide a little insite:
                >
                > 1) What two chars have to be escaped when performing a
                > document.write( )?[/color]

                I 'd have mentioned the ampersand instead of the other pair of quotes (not
                used for delimiting the current string). Not directly sure why tho. Come to
                think of it, what a silly question it is! Doesn't it depend on what you are
                about to write? If the text includes an umlaut or a less-than character...
                [color=blue]
                > 2) What is the main thing that has to be done when performing a
                > document.write( ) in a script block?[/color]

                It 's suspicious that they 're so interested in document.write, which method
                has always been a bit cumbersome and is not even available in the latest
                doctypes. I guess he meant what has to be done is make sure that the
                document isn't already closed, ie. you 're not overwriting the current page,
                as that is the usual problem with document.write.

                But really, these types of questions say more about the questioner than any
                answer sais about the candidate. Not sure if I 'd be happy to work there.
                Ivo


                Comment

                • Richard Cornford

                  #9
                  Re: Job Interview Questions

                  Jim Ley wrote:[color=blue]
                  > Chu wrote:
                  >[color=green]
                  >>Recently in a job interview I was asked the following
                  >>questions. I was able to answer the first one, but the
                  >>2nd one still baffles me. I'm curious if anyone can
                  >> provide a little insite:
                  >>
                  >>1) What two chars have to be escaped when performing a
                  >>document.writ e()?
                  >>
                  >>I answered that quotes, both single and double need to be
                  >>escaped when they are supposed to be part of the output of
                  >>a document.write statement.[/color]
                  >
                  > There's lots of others too, newlines and other newline
                  > like things from unicode for example, others depending on
                  > if the document.write is inside an XML org SGML document,
                  > but that's probably what the incompetent test setter was
                  > wanting, javascript tests are almost universally appalling.[/color]

                  I also would have thought it was line terminators that _must_ be escaped
                  in a string literal within document.write (and any other string literal
                  as well) as a line terminator in a string literal is a syntax error.
                  There are 4 line terminators in ECMA 262. All other characters only need
                  escaping under some circumstances.
                  [color=blue][color=green]
                  >>2) What is the main thing that has to be done when
                  >>performing a document.write( ) in a script block?[/color]
                  >
                  > nothing, it's a gibberish question,[/color]

                  Well maybe they meant "</script>" as that would likely be problematic in
                  a string literal in a document.write statement within a SCRIPT element
                  on an HTML page. Though again it is more to do with string literals than
                  with document.write. And of course the sequence that should be escaped
                  is the CDATA terminating "</"
                  [color=blue]
                  > the man is either completely clueless,
                  > or trying to throw you to see your reaction.[/color]

                  I wonder whether a clueless test setter, encountering a candidate who
                  evidently knew javascript better than them, would see it as in their
                  interest to employ them.

                  Richard.


                  Comment

                  • Csaba Gabor

                    #10
                    Re: Job Interview Questions

                    Chu wrote:[color=blue]
                    > 2) What is the main thing that has to be done when performing a
                    > document.write( ) in a script block?[/color]

                    I don't know about main thing, but one thing to watch out for is that
                    when you start doing the document.write( ), it obliterates the old
                    document (more or less). However, the script blocks and their local
                    variables are OK (I haven't actually looked at what specs might say on
                    this - so they may say otherwise). To that end, I would say that it is
                    advisable to constuct a single string that you are going to 'blat' as
                    the new document before the document.open or any writing. And I would
                    only do a single document.write( ) to be on the safe side.

                    Consider the following:
                    <body onLoad='selfAdj ust()'>
                    <script type='text/javascript'>
                    function selfAdjust() {
                    alertPre = "old div had: ";
                    var div = document.getEle mentById('mydiv ');
                    var preScript = "<body><scr ipt type='text/javascript'>ale rt('";
                    document.open() ;
                    var part2 = alertPre + div.innerHTML + "');<\/script></body>";
                    document.write( preScript + part2);
                    document.close( );
                    }
                    </script>
                    <div id=mydiv>Hi Mom</div>
                    </body>

                    This will fail because alertPre is global (sitting off window) and
                    document.open() will wipe it out. If you have, instead, var alertPre =
                    "old div had: "; then that part won't throw an error.

                    There is second point of failure, and that is the issue of what is
                    happening with that div when you wipe out its (old) document. Actually
                    this does not fail in FF, presumably FF realizes you have a reference
                    to the object, even if it is somewhat orphan by this point. However,
                    in IE 6, an empty string is plunked in.

                    Csaba Gabor from Vienna

                    Comment

                    • Matt Kruse

                      #11
                      Re: Job Interview Questions

                      Chu wrote:[color=blue]
                      > 1) What two chars have to be escaped when performing a
                      > document.write( )?[/color]

                      Others have answered, but I would have said:

                      1) The quoted string character - either ' or "

                      2) Any character starting with a back-slash (\, \n, \t, etc)

                      Stupid question, though.

                      --
                      Matt Kruse




                      Comment

                      • Lee

                        #12
                        Re: Job Interview Questions

                        Chu said:[color=blue]
                        >
                        >Recently in a job interview I was asked the following questions. I was
                        >able to answer the first one, but the 2nd one still baffles me. I'm
                        >curious if anyone can provide a little insite:
                        >
                        >1) What two chars have to be escaped when performing a
                        >document.write ()?[/color]
                        [color=blue]
                        >2) What is the main thing that has to be done when performing a
                        >document.write () in a script block?[/color]

                        If I had asked these questions, it would have been to hear you
                        discuss them, much as they've been discussed here, more than to
                        hear your guess as to what I might think the "main" thing was.

                        But if they consider there to be exactly two characters that
                        need to be escaped, I would say they're looking for " and \,
                        and I wonder if they might believe that "document.close ()" is
                        always required.

                        Comment

                        Working...