edit-article
Home
Up
Delete
Article Name:
Article Description:
javascript interview questions ] by Vikas Ahlawat @CodeProject.com, src=g.qry(js interview questions), includes my answers, the answers
Chapter ID/Name:
Status:
Write
Writing
Written
Add Photo:
Owner ID:
Content:
use HTML
Edit Content
<h1 style="text-align: center;">javascript interview questions - part 2</h1> <h2>[WHAT]</h2> <ol> <li><strong>] here is a list of some javascript interview questions(31),</strong></li> <ol> <li>] ADD this compiled from a number of sources, along with my answer,and their(the original sites) answer</li> </ol> <li><strong>] Although these are relatively simple questions,</strong></li> <ol> <li>] working through them was beneficial for me as I stumbled upon a few of them because my native js tongue is jquery and</li> </ol> <li><strong>] i like the (softball) easy coding questions BUT if I was interviewing someone for a js programming position,</strong></li> <ol> <li>] I think just having them submit a code sample along with their application would be a much quicker</li> <li>] EXAMPLE REQUEST - please include a sample of a javascript function that you wrote that demonstrates ( ] use of an array, ] creating the array and accessing elements of the array )</li> <li>] YES i realize that the code submitted could be c+p from 'anywhere' but ...</li> </ol></ol> <h2>[WHY]</h2> <ol> <li>]</li> </ol> <h2>[WHERE]</h2> <ol> <li><strong>] READ THE FULL ARTICLE</strong></li> <ol> <li> <a href="http://www.codeproject.com/Articles/620811/Latest-JavaScript-Interview-Questions-and-Answers" target="_blank">http://www.codeproject.com/Articles/620811/Latest-JavaScript-Interview-Questions-and-Answers</a></li> </ol></ol> <p>[WHEN]</p> <p>[EXAMPLE]</p> <p>[HOW-TO]</p> <h2>[REFERENCE]</h2> <ol> <li>] <a href="http://www.codeproject.com/Articles/620811/Latest-JavaScript-Interview-Questions-and-Answers" target="_blank">http://www.codeproject.com/Articles/620811/Latest-JavaScript-Interview-Questions-and-Answers</a></li> <ol> <li>by Vikas Ahlawat 2013-08-26</li> <li>src = g.qry "js interview questions", result # 2</li> </ol> <li><strong>] <a href="/view/article?id=2616" target="_blank">javascript-interview-questions-part-1</a></strong></li> <ol> <li>by</li> <li>src =</li> </ol></ol><hr /> <p style="text-align: left;"> </p> <ol> <li> <div style="text-align: left;"><strong>] what is <a href="/view/article?id=1662" target="_blank">javascript</a></strong></div> </li> <ol> <li> <div style="text-align: left;">] programming language, loosely typed, uses c like syntax, interpreted, based upon ?lisp? ] creator Brendan Eich(@netsape), started on the web circa 1996, to manipulate html/dom in the browser, grew exponentially, ubiqutious,</div> </li> <li> <div style="text-align: left;">] Ans:JavaScript is a scripting language most often used for client-side web development.</div> </li> </ol> <li> <div style="text-align: left;"><strong>] what is the difference between javascript and jscript?</strong></div> </li> <ol> <li> <div style="text-align: left;">] jscript is msft implementation of the javascript specification(ecmascript), each brower vendor creates it own implementation of the ecmascript standard (current v= ?262.5?)</div> </li> <li> <div style="text-align: left;">] Ans:Both JavaScript and Jscript are almost similar. JavaScript was developed by Netscape. Microsoft reverse engineered Javascript and called it JScript.</div> </li> </ol> <li> <div style="text-align: left;"><strong>] how do we add javascript onto a web page?</strong></div> </li> <ol> <li> <div style="text-align: left;">] write a js file then link that file to your page<head> <script type="text/javascript "src="path"/> </head> OR before the closing body tag // ] write a js script inside of the head of your page // ] write a js script inline inside the body of the page using <script> tags</div> </li> <li> <div style="text-align: left;">] for short single use scripts put in head of your page, for larger scripts, write a js files and link</div> </li> </ol> <li> <div style="text-align: left;"><strong>] is javascript case sensitive?</strong></div> </li> <ol> <li> <div style="text-align: left;">] yes - js is very sensitive,</div> </li> <li> <div style="text-align: left;">] yes - getElementById IS NOT the same as getElementByID</div> </li> </ol> <li> <div style="text-align: left;"><strong>] What are the 'types' used in javascript?</strong></div> </li> <ol> <li> <div style="text-align: left;">] String, Number, Math, Array, Function, Boolean, Object, RegEx ?? ( Null, Undefined ) Array type ??</div> </li> <li> <div>] Ans:<code>String</code>, <code>Number</code>, <code>Boolean</code>, <code>Function</code>, <code>Object</code>, <code>Null</code>, <code>Undefined</code>.</div> </li> </ol> <li> <div><strong>?? ] What art the boolean operators supported by the js AND operator &&</strong></div> </li> <ol> <li> <div>] x < 10 && ( >,<, ===, !===, )</div> </li> <li> <div>] OR operator || NOT operator - !</div> </li> </ol> <li> <div><strong>] What is the difference between == and ===</strong></div> </li> <ol> <li> <div>] == can cause problems because ..., always use ===</div> </li> <li> <div>] == checks for equality only, === checks for equality and type</div> </li> </ol> <li> <div><strong>] how to access the value of a textbox using javascript?</strong></div> </li> <ol> <li> <div>] var textBoxValue = getElementById('textboxid').value; // document.getElementById</div> </li> <li> <div>] document.getElementById(...) //</div> </li> </ol> <li> <div><strong>] What are the ways of making comments in js?</strong></div> </li> <ol> <li> <div>] // single line, /* multi line */</div> </li> <li> <div>] // line comments /* block comments */</div> </li> </ol> <li> <div><strong>x] how will you get the checkbox status, wether it is checked or not?</strong></div> </li> <ol> <li> <div>] if (document.getElementById('checkBox1').checked === 'checked' ) {alert("checked");}else{alert("not checked");} // value = true, // ] $("checkBox").val('true')</div> </li> <li> <div>] document.getElementById('checkBox1').checked returns true OR false</div> </li> </ol> <li> <div><strong>] how to create <a href="/view/article?id=1695" target="_blank">arrays</a> in javascript?</strong></div> </li> <ol> <li> <div>] var cats = new Array("chester","harly","carly"); // object literal var cats = ["chester","harly","carly"] // var cats = new Array(); cats[0] = "chester";</div> </li> </ol> <li> <div>] <strong>If an array with name as "names" contain three elements, then how will you print the third element of this array?</strong></div> </li> <ol> <li>] alert(names[2]);</li> <li>] Ans: Print third array element <code>document.write(names[2]);</code></li> </ol> <li> <div><strong>] How do you submit a form using JavaScript?</strong></div> </li> <ol> <li> <div>] document.getElementById('idForm').submit() // $('idForm').submit()</div> </li> <li> <div>] Ans:Use document.forms[0].submit();</div> </li> </ol> <li> <div><strong>] what does the 'isNan' function do?</strong></div> </li> <ol> <li> <div>] determines if a value is a Number type or not</div> </li> <li> <div>] It returns true if the argument is not a number.</div> </li> </ol> <li> <div><strong>] What is the use of <a href="/view/article?id=1695" target="_blank">Math</a> Object in JavaScript?</strong></div> </li> <ol> <li> <div>] Math is a native js object that contains a collection of Mathematical functions you can use in your program, var randomNumber = Math.Random();</div> </li> <li> <div>] The math object provides you properties and methods for mathematical constants and functions</div> </li> </ol> <li> <div><strong>] What do you understand by <a href="/view/article?id=2617" target="_blank">this</a> keyword in JavaScript?</strong></div> </li> <ol> <li> <div>] this is a js keyword, you can use 'this' as a shortcut to reference the 'currently in scope' object's properties and methods, its invaluable b/c it enables you to id which option (of any number of options) that is currently active/selected by user</div> </li> <li> <div>] Ans: In JavaScript the <code>this</code> is a context-pointer and not an object pointer. It gives you the top-most context that is placed on the stack. The following gives two different results (in the browser, where by-default the <code>window</code> object is the 0-level context):</div> </li> <li> <div><span class="code-keyword">var</span> obj = { outerWidth : <span class="code-digit">20</span> };<br /> <span class="code-keyword">function</span> say() {<br /> alert(<span class="code-keyword">this</span>.outerWidth);<br />}<br /> say();<span class="code-comment">//</span><span class="code-comment">will alert window.outerWidth </span>say.apply(obj);<span class="code-comment">//</span><span class="code-comment">will alert obj.outerWidth</span></div> </li> </ol> <li> <div><strong>) What does "1"+2+4 evaluate to?</strong></div> </li> <ol> <li> <div>] returns string "124", because "1" is a string, everything is treated as a string</div> </li> <li> <div>] Ans: Since <code>1 </code>is a <code>string</code>, everything is a <code>string</code>, so the result is <code>124</code>.</div> </li> </ol> <li> <div><strong>] What does 3+4+"7" evaluate to?</strong></div> </li> <ol> <li> <div>x] returns 77 because ...</div> </li> <li> <div>Ans: Since <code>3 </code>and <code>4 </code>are integers, this is number arithmetic, since <code>7 </code>is a <code>string</code>, it is concatenation, so <code>77 </code>is the result.</div> </li> </ol> <li> <div><strong>] How do you change the style/class on any element using JavaScript?</strong></div> </li> <ol> <li> <div>] document.getElementById('element').setAttribute("class","newClassName");</div> </li> <li> <div>] document.getElementById(“myText”).style.fontSize = “10<span class="code-string">"</span><span class="code-string">; OR document.getElementById(“myText”).className = “anyclass”;</span></div> </li> </ol> <li> <div>X]<strong> Does JavaScript support foreach loop?</strong></div> </li> <ol> <li> <div>] no</div> </li> <li> <div><strong>] </strong>Ans: JavaScript 1.6(ECMAScript 5th Edition) support foreach loop,</div> </li> </ol> <li> <div><strong>] What looping structures are there in JavaScript?</strong></div> </li> <ol> <li> <div>] for, for each in, for in, for of, do while, while</div> </li> <li> <div>] Ans: for, while, do-while loops</div> </li> </ol> <li> <div><strong>] What is an object in JavaScript, give an example?</strong></div> </li> <ol> <li> <div>] everything in js is an object, if were talking in the language itself, Number, Date, String, ... are all objects</div> </li> <li> <div>] Ans: An object is just a container for a collection of named values:</div> </li> <ol> <li> <div><span class="code-keyword">var</span> man = <span class="code-keyword">new</span> Object();</div> </li> <li> <div>man.name = <span class="code-string">'</span><span class="code-string">Vikas Ahlawat'</span>;</div> </li> <li> <div>man.living = <span class="code-keyword">true</span>;</div> </li> <li> <div>man.age = <span class="code-digit">27</span>;</div> </li> </ol></ol> <li> <div><strong>] How you will add function as a property in a JavaScript object? Give an example.</strong></div> </li> <ol> <li> <div>] man.showAge = function() {alert(this.age);};</div> </li> <li> <div>]</div> </li> </ol> <li> <div><strong>] What is the similarity between the 1st and 2nd statement?</strong></div> </li> <ol> <li> <div>1st:- var myString = new String('male'); // An object.</div> </li> <li> <div>2nd:- var myStringLiteral = 'male'; // Primitive string value, not an object.</div> </li> <li> <div>] both create a new string object, the 2nd while classified as a Primitive, still has an object wrapper that gives you the String objects functionality (lenght, ...) </div> </li> </ol></ol>