Interview Question


Country: United States




Comment hidden because of low score. Click to expand.
0
of 0 vote

Both the href and the on click are calling JavaScript funtions. The href cancels out the do something function.

- TheShocker1999 December 02, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Interestingly, when I run on jsfiddle - clk() function is called.
<script>
function clk(){
//console.log("here");
confirm("here");
}

</script>

<a href="javascript:void(0)" onClick="return clk()">Click me</a>

- princary December 02, 2015 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Nothing good, its a bad practrice...

It's trying to prevent the default behavior of an anchor element and execute some script instead.

- From the semantics point of view:
An anchor tag should "link" (for example to a document or an specific location of the current document), if we are looking to perform a custom action the element should be a button, not an anchor.

- From the "Separation of concerns" point of view
Using inline scripts is discouraged, that practice leads to a non-maintainable code and in fact its just a hack. Attaching an event listener and preventing the default would be the way to go.

- Content Security Policy
On sites where configured, CSP will block inline scripts execution, therefore this wouldn't work...

- Fab December 02, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

It's realy hard to block xss in doSomething() if you use data which the user can manipulate (query param or something stored in the DB). It's hard to sanatize your data in that case

- bob December 03, 2015 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More