473,325 Members | 2,816 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

Job Interview Questions

Chu
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?

Jul 23 '05 #1
11 1393
On 19 Jun 2005 14:16:43 -0700, "Chu" <ry**@thescottclan.net> wrote:
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.
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.
2) What is the main thing that has to be done when performing a
document.write() in a script block?


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

Jim.
Jul 23 '05 #2
Quoth Chu:
2) What is the main thing that has to be done when performing a
document.write() in a script block?


Flush the buffer, of course.

--
\\kristian
Jul 23 '05 #3
Chu
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?

Jul 23 '05 #4
On 19 Jun 2005 21:39:04 GMT, Kristian Thy <th*@itu.dk> wrote:
Quoth Chu:
2) What is the main thing that has to be done when performing a
document.write() in a script block?


Flush the buffer, of course.


And how do you do that exactly?

Jim.
Jul 23 '05 #5
Quoth Jim Ley:
On 19 Jun 2005 21:39:04 GMT, Kristian Thy <th*@itu.dk> wrote:
Quoth Chu:
2) What is the main thing that has to be done when performing a
document.write() in a script block?


Flush the buffer, of course.


And how do you do that exactly?


You start by adjusting your sarcasmometer ...

--
\\kristian
Jul 23 '05 #6
"Chu" <ry**@thescottclan.net> writes:
Recently in a job interview I was asked the following questions.
That happens a lot these days, it seems.
1) What two chars have to be escaped when performing a
document.write()?
My immediate response would have been "what do you mean?"
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.
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.
He seemed happy with that response.
It's one way to understand a vague question :)
2) What is the main thing that has to be done when performing a
document.write() in a script block?
Call "document.write"? Or my next response: "What *are* you talking
about?!?".
I had no clue. The question seems pretty vague...


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 - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 23 '05 #7
Ivo
"Chu" <ry**@thescottclan.net> wrote
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 '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...
2) What is the main thing that has to be done when performing a
document.write() in a script block?


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
Jul 23 '05 #8
Jim Ley wrote:
Chu wrote:
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.
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.


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.
2) What is the main thing that has to be done when
performing a document.write() in a script block?


nothing, it's a gibberish question,


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 "</"
the man is either completely clueless,
or trying to throw you to see your reaction.


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.
Jul 23 '05 #9
Chu wrote:
2) What is the main thing that has to be done when performing a
document.write() in a script block?


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='selfAdjust()'>
<script type='text/javascript'>
function selfAdjust() {
alertPre = "old div had: ";
var div = document.getElementById('mydiv');
var preScript = "<body><script type='text/javascript'>alert('";
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

Jul 23 '05 #10
Chu wrote:
1) What two chars have to be escaped when performing a
document.write()?


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
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com
Jul 23 '05 #11
Lee
Chu said:

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()? 2) What is the main thing that has to be done when performing a
document.write() in a script block?


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.

Jul 23 '05 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: softwareengineer2006 | last post by:
All Interview Questions And Answers 10000 Interview Questions And Answers(C,C++,JAVA,DOTNET,Oracle,SAP) I have listed over 10000 interview questions asked in interview/placement test papers for...
0
by: Jobs | last post by:
Download the JAVA , .NET and SQL Server interview sheet and rate yourself. This will help you judge yourself are you really worth of attending interviews. If you own a company best way to judge if...
2
by: Jobs | last post by:
Download the JAVA , .NET and SQL Server interview with answers Download the JAVA , .NET and SQL Server interview sheet and rate yourself. This will help you judge yourself are you really worth of...
0
by: connectrajesh | last post by:
INTERVIEWINFO.NET http://www.interviewinfo.net FREE WEB SITE AND SERVICE FOR JOB SEEKERS /FRESH GRADUATES NO ADVERTISEMENT
2
by: freepdfforjobs | last post by:
Full eBook with 4000 C#, JAVA,.NET and SQL Server Interview questions http://www.questpond.com/SampleInterviewQuestionBook.zip Download the JAVA , .NET and SQL Server interview sheet and rate...
0
by: freesoftwarepdfs | last post by:
Ultimate list of Interview question website.....Do not miss it http://www.questpond.com http://msdotnetsupport.blogspot.com/2007/01/net-interview-questions-by-dutt-part-2.html...
0
by: ramu | last post by:
C# Interview Questions and Answers8 http://allinterviewsbooks.blogspot.com/2008/07/c-interview-questions-and-answers8.html C# Interview Questions and Answers7...
0
by: reema | last post by:
EJB Interview Questions http://interviewdoor.com/technical/EJB-Interview-Questions.htm CSS Interview Questions http://interviewdoor.com/technical/CSS-Interview-Questions.htm C Interview Questions...
0
by: reema | last post by:
EJB Interview Questions http://interviewdoor.com/technical/EJB-Interview-Questions.htm CSS Interview Questions http://interviewdoor.com/technical/CSS-Interview-Questions.htm C Interview Questions...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.