{"id":26405,"date":"2022-02-08T10:49:38","date_gmt":"2022-02-08T10:49:38","guid":{"rendered":"https:\/\/www.devopsschool.com\/blog\/?p=26405"},"modified":"2022-04-13T16:55:36","modified_gmt":"2022-04-13T16:55:36","slug":"top-50-interview-question-and-answers-for-javascript","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/top-50-interview-question-and-answers-for-javascript\/","title":{"rendered":"Top 50 interview question and answers for JavaScript"},"content":{"rendered":"\n<p>JavaScript could be a scripting or artificial language that enables you to implement advanced options on websites each time an internet page will quite simply sit there and show static info for you to seem at displaying timely content updates, interactive maps, animated 2D\/3D graphics, scrolling video jukeboxes, etc. you&#8217;ll be able to bet that JavaScript is maybe concerned. It\u2019s the third layer of the cake of normal net technologies, 2 of that (HTML and CSS) we&#8217;ve lived in rather more detail in alternative elements of the training space.<\/p>\n\n\n\n<p>So, without wasting anymore time, let\u2019s begin with our topic of FAQ, interview questions and answers!<\/p>\n\n\n\n<p><strong>FAQ and interview questions and answers for JavaScript:-<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\" type=\"1\"><li><strong>What is JavaScript?<\/strong><\/li><\/ol>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"800\" height=\"300\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/02\/javascript-illustration.png\" alt=\"\" class=\"wp-image-26415\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/02\/javascript-illustration.png 800w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/02\/javascript-illustration-300x113.png 300w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/02\/javascript-illustration-768x288.png 768w\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" \/><figcaption>what is javascript<\/figcaption><\/figure>\n\n\n\n<p>JavaScript is a lightweight, interpreted programming language with object-oriented capabilities that allows you to build interactivity into otherwise static HTML pages. The general-purpose core of the language has been embedded in Netscape, Internet Explorer, and other web browsers.<\/p>\n\n\n\n<p>2. <strong>What are the data types supported by JavaScript?<\/strong><\/p>\n\n\n\n<p>The data types supported by JavaScript are:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Undefined<\/li><li>Null<\/li><li>Boolean<\/li><li>String<\/li><li>Symbol<\/li><li>Number<\/li><li>Object<\/li><\/ul>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>&nbsp;What are the features of JavaScript?<\/strong><\/li><\/ul>\n\n\n\n<p>Following are the features of JavaScript:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>It is a lightweight, interpreted programming language.<\/li><li>It is designed for creating network-centric applications.<\/li><li>It is complementary to and integrated with Java.<\/li><li>It is an open and cross-platform scripting language. <\/li><\/ul>\n\n\n\n<p>3. I<strong>s JavaScript a case-sensitive language?<\/strong><\/p>\n\n\n\n<p>Yes, JavaScript is a case sensitive language.\u00a0 The language keywords, variables, function names, and any other identifiers must always be typed with a consistent capitalization of letters.<\/p>\n\n\n\n<p>4. <strong>What are the advantages of JavaScript?<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/02\/introduction-to-javascript-basics-3-638.jpg\" alt=\"\" class=\"wp-image-26417\" width=\"766\" height=\"431\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/02\/introduction-to-javascript-basics-3-638.jpg 638w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/02\/introduction-to-javascript-basics-3-638-300x169.jpg 300w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/02\/introduction-to-javascript-basics-3-638-355x199.jpg 355w\" sizes=\"auto, (max-width: 766px) 100vw, 766px\" \/><figcaption>advantages of javascript<\/figcaption><\/figure>\n\n\n\n<p>Following are the advantages of using JavaScript \u2212<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Less server interaction \u2212 you can validate user input before sending the page off to the server. This saves server traffic, which means less load on your server.<\/li><li>Immediate feedback to the visitors \u2212 they don\u2019t have to wait for a page reload to see if they have forgotten to enter something.<\/li><li>Increased interactivity \u2212 you can create interfaces that react when the user hovers over them with a mouse or activates them via the keyboard.<\/li><li>Richer interfaces \u2212 you can use JavaScript to include such items as drag-and-drop components and sliders to give a Rich Interface to your site visitors. <\/li><\/ul>\n\n\n\n<p> 5.<strong>How can you create an object in JavaScript?<\/strong><\/p>\n\n\n\n<p>JavaScript supports Object concept very well. You can create an object using the object literal as follows \u2212<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\"><span class=\"hljs-keyword\">var<\/span> emp = {\r\n<span class=\"hljs-attr\">name<\/span>: <span class=\"hljs-string\">\"Daniel\"<\/span>,\r\n<span class=\"hljs-attr\">age<\/span>: <span class=\"hljs-number\">23<\/span>\r\n};\r\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<ol class=\"wp-block-list\" type=\"1\"><li><strong>What are undeclared and undefined variables?<\/strong><\/li><\/ol>\n\n\n\n<p>Undeclared variables are those that do not exist in a program and are not declared. If the program tries to read the value of an undeclared variable, then a runtime error is encountered.<\/p>\n\n\n\n<p>Undefined variables are those that are declared in the program but have not been given any value. If the program tries to read the value of an undefined variable, an undefined value is returned.<\/p>\n\n\n\n<p>7. <strong>Write the code for adding new elements dynamically?<\/strong><\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"HTML, XML\" data-shcb-language-slug=\"xml\"><span><code class=\"hljs language-xml\"><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">html<\/span>&gt;<\/span> \r\n<span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">head<\/span>&gt;<\/span> \r\n<span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">title<\/span>&gt;<\/span>t1<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">title<\/span>&gt;<\/span> \r\n<span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">script<\/span> <span class=\"hljs-attr\">type<\/span>=<span class=\"hljs-string\">\"text\/javascript\"<\/span>&gt;<\/span><span class=\"javascript\"> \r\n    <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> <span class=\"hljs-title\">addNode<\/span> (<span class=\"hljs-params\"><\/span>) <\/span>{ <span class=\"hljs-keyword\">var<\/span> newP = <span class=\"hljs-built_in\">document<\/span>. createElement(<span class=\"hljs-string\">\"p\"<\/span>); \r\n    <span class=\"hljs-keyword\">var<\/span> textNode = <span class=\"hljs-built_in\">document<\/span>.createTextNode(<span class=\"hljs-string\">\" This is a new text node\"<\/span>); \r\n    newP.appendChild(textNode); <span class=\"hljs-built_in\">document<\/span>.getElementById(<span class=\"hljs-string\">\"firstP\"<\/span>).appendChild(newP); } \r\n<\/span><span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">script<\/span>&gt;<\/span> <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">head<\/span>&gt;<\/span> \r\n<span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">body<\/span>&gt;<\/span> <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">p<\/span> <span class=\"hljs-attr\">id<\/span>=<span class=\"hljs-string\">\"firstP\"<\/span>&gt;<\/span>firstP<span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">p<\/span>&gt;<\/span> <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">body<\/span>&gt;<\/span> \r\n<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">html<\/span>&gt;<\/span>\r\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">HTML, XML<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">xml<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p><strong>8. \u00a0What are global variables? How are these variable declared?<\/strong><\/p>\n\n\n\n<p>Global variables are available throughout the length of the code so that it has no scope. The var keyword is used to declare a local variable or object. If the var keyword is omitted, a global variable is declared.<\/p>\n\n\n\n<p>Example:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"JSON \/ JSON with Comments\" data-shcb-language-slug=\"json\"><span><code class=\"hljs language-json\"><span class=\"hljs-comment\">\/\/ Declare a global: globalVariable = \u201cTest\u201d;<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JSON \/ JSON with Comments<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">json<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>The problems faced by using global variables are the clash of variable names of local and global scope. Also, it is difficult to debug and test the code that relies on global variables.<\/p>\n\n\n\n<p>9. <strong>What is a prompt box?<\/strong><\/p>\n\n\n\n<p>A prompt box is a box that allows the user to enter input by providing a text box. A label and box will be provided to enter the text or number.<\/p>\n\n\n\n<p>10. <strong>What is \u2018this\u2019 keyword in JavaScript?<\/strong><\/p>\n\n\n\n<p>\u2018This\u2019 keyword refers to the object from where it was called.<strong>\u00a0What is the working of timers in JavaScript?<\/strong><\/p>\n\n\n\n<p>Timers are used to execute a piece of code at a set time or repeat the code in a given interval. This is done by using the functions setTimeout, setInterval, and clearInterval.<\/p>\n\n\n\n<p>The setTimeout(function, delay) function is used to start a timer that calls a particular function after the mentioned delay. The setInterval(function, delay) function repeatedly executes the given function in the mentioned delay and only halts when canceled. The clearInterval(id) function instructs the timer to stop.<\/p>\n\n\n\n<p>Timers are operated within a single thread, and thus events might queue up, waiting to be executed.<\/p>\n\n\n\n<p>12. <strong>Which symbol is used for comments in JavaScript?<\/strong><\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"JSON \/ JSON with Comments\" data-shcb-language-slug=\"json\"><span><code class=\"hljs language-json\"><span class=\"hljs-comment\">\/\/ for Single line comments and<\/span>\r\n<span class=\"hljs-comment\">\/* Multi\r\nLine\r\nComment\r\n*\/<\/span>\r\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JSON \/ JSON with Comments<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">json<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p><strong>\u2018<\/strong><\/p>\n\n\n\n<p>13. <strong>What is the difference between ViewState and SessionState?<\/strong><\/p>\n\n\n\n<p>ViewState\u2019 is specific to a page in a session.<\/p>\n\n\n\n<p>\u2018SessionState\u2019 is specific to user-specific data that can be accessed across all web application page<\/p>\n\n\n\n<p>14. <strong>\u00a0What is === operator?<\/strong><\/p>\n\n\n\n<p>=== is called a strict equality operator, which returns true when the two operands have the same value without conversion<\/p>\n\n\n\n<p>15. <strong>\u00a0\u00a0How you can submit a form using JavaScript?<\/strong><\/p>\n\n\n\n<p>To submit a form using JavaScript use<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css\"><span class=\"hljs-selector-tag\">document<\/span><span class=\"hljs-selector-class\">.form<\/span><span class=\"hljs-selector-attr\">&#91;0]<\/span><span class=\"hljs-selector-class\">.submit<\/span>();\r\n<span class=\"hljs-selector-tag\">document<\/span><span class=\"hljs-selector-class\">.form<\/span><span class=\"hljs-selector-attr\">&#91;0]<\/span><span class=\"hljs-selector-class\">.submit<\/span>();\r\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>16. <strong>Does JavaScript support automatic type conversion?<\/strong><\/p>\n\n\n\n<p>Yes, JavaScript does support automatic type conversion. It is the common way of type conversion used by JavaScript developers<\/p>\n\n\n\n<p><strong>\u00a017. How can the style\/class of an element be changed?<\/strong><\/p>\n\n\n\n<p><strong>It can be done in the following way:<\/strong><\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-6\" data-shcb-language-name=\"HTML, XML\" data-shcb-language-slug=\"xml\"><span><code class=\"hljs language-xml\">document.getElementById(\"myText\"). style. fontSize = \"20\";\r\nor\r\ndocument. getElementById (\"myText\"). className = \"anyclass\";\r\nHow to validate a form in JavaScript?\r\n<span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">script<\/span>&gt;<\/span><span class=\"javascript\">  \r\n<span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> <span class=\"hljs-title\">validateform<\/span>(<span class=\"hljs-params\"><\/span>)<\/span>{  \r\n<span class=\"hljs-keyword\">var<\/span> name=<span class=\"hljs-built_in\">document<\/span>.myform.name.value;  \r\n<span class=\"hljs-keyword\">var<\/span> password=<span class=\"hljs-built_in\">document<\/span>.myform.password.value;  \r\n  \r\n<span class=\"hljs-keyword\">if<\/span> (name==<span class=\"hljs-literal\">null<\/span> || name==<span class=\"hljs-string\">\"\"<\/span>){  \r\n  alert(<span class=\"hljs-string\">\"Name can't be blank\"<\/span>);  \r\n  <span class=\"hljs-keyword\">return<\/span> <span class=\"hljs-literal\">false<\/span>;  \r\n}<span class=\"hljs-keyword\">else<\/span> <span class=\"hljs-keyword\">if<\/span>(password.length&lt;<span class=\"hljs-number\">6<\/span>){  \r\n  alert(<span class=\"hljs-string\">\"Password must be at least 6 characters long.\"<\/span>);  \r\n  <span class=\"hljs-keyword\">return<\/span> <span class=\"hljs-literal\">false<\/span>;  \r\n  }  \r\n}  \r\n<\/span><span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">script<\/span>&gt;<\/span>  \r\n<span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">body<\/span>&gt;<\/span>  \r\n<span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">form<\/span> <span class=\"hljs-attr\">name<\/span>=<span class=\"hljs-string\">\"myform\"<\/span> <span class=\"hljs-attr\">method<\/span>=<span class=\"hljs-string\">\"post\"<\/span> <span class=\"hljs-attr\">action<\/span>=<span class=\"hljs-string\">\"abc.jsp\"<\/span> <span class=\"hljs-attr\">onsubmit<\/span>=<span class=\"hljs-string\">\"return validateform()\"<\/span> &gt;<\/span>  \r\nName: <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">input<\/span> <span class=\"hljs-attr\">type<\/span>=<span class=\"hljs-string\">\"text\"<\/span> <span class=\"hljs-attr\">name<\/span>=<span class=\"hljs-string\">\"name\"<\/span>&gt;<\/span><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">br<\/span>\/&gt;<\/span>  \r\nPassword: <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">input<\/span> <span class=\"hljs-attr\">type<\/span>=<span class=\"hljs-string\">\"password\"<\/span> <span class=\"hljs-attr\">name<\/span>=<span class=\"hljs-string\">\"password\"<\/span>&gt;<\/span><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">br<\/span>\/&gt;<\/span>  \r\n<span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">input<\/span> <span class=\"hljs-attr\">type<\/span>=<span class=\"hljs-string\">\"submit\"<\/span> <span class=\"hljs-attr\">value<\/span>=<span class=\"hljs-string\">\"register\"<\/span>&gt;<\/span>  \r\n<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">form<\/span>&gt;<\/span>  \r\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-6\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">HTML, XML<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">xml<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>18. <strong>How to validate email in JavaScript?<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"351\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/02\/output-2-1-1024x351.png\" alt=\"\" class=\"wp-image-26419\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/02\/output-2-1-1024x351.png 1024w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/02\/output-2-1-300x103.png 300w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/02\/output-2-1-768x264.png 768w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/02\/output-2-1.png 1256w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-7\" data-shcb-language-name=\"HTML, XML\" data-shcb-language-slug=\"xml\"><span><code class=\"hljs language-xml\">\n<span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">script<\/span>&gt;<\/span><span class=\"javascript\">  \r\n<span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> <span class=\"hljs-title\">validateemail<\/span>(<span class=\"hljs-params\"><\/span>)  \r\n<\/span>{  \r\n<span class=\"hljs-keyword\">var<\/span> x=<span class=\"hljs-built_in\">document<\/span>.myform.email.value;  \r\n<span class=\"hljs-keyword\">var<\/span> atposition=x.indexOf(<span class=\"hljs-string\">\"@\"<\/span>);  \r\n<span class=\"hljs-keyword\">var<\/span> dotposition=x.lastIndexOf(<span class=\"hljs-string\">\".\"<\/span>);  \r\n<span class=\"hljs-keyword\">if<\/span> (atposition&lt;<span class=\"hljs-number\">1<\/span> || dotposition&lt;atposition+<span class=\"hljs-number\">2<\/span> || dotposition+<span class=\"hljs-number\">2<\/span>&gt;=x.length){  \r\n  alert(<span class=\"hljs-string\">\"Please enter a valid e-mail address \\n atpostion:\"<\/span>+atposition+<span class=\"hljs-string\">\"\\n dotposition:\"<\/span>+dotposition);  \r\n  <span class=\"hljs-keyword\">return<\/span> <span class=\"hljs-literal\">false<\/span>;  \r\n  }  \r\n}  \r\n<\/span><span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">script<\/span>&gt;<\/span>  \r\n<span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">body<\/span>&gt;<\/span>  \r\n<span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">form<\/span> <span class=\"hljs-attr\">name<\/span>=<span class=\"hljs-string\">\"myform\"<\/span>  <span class=\"hljs-attr\">method<\/span>=<span class=\"hljs-string\">\"post\"<\/span> <span class=\"hljs-attr\">action<\/span>=<span class=\"hljs-string\">\"#\"<\/span> <span class=\"hljs-attr\">onsubmit<\/span>=<span class=\"hljs-string\">\"return validateemail();\"<\/span>&gt;<\/span>  \r\nEmail: <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">input<\/span> <span class=\"hljs-attr\">type<\/span>=<span class=\"hljs-string\">\"text\"<\/span> <span class=\"hljs-attr\">name<\/span>=<span class=\"hljs-string\">\"email\"<\/span>&gt;<\/span><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">br<\/span>\/&gt;<\/span>  \r\n  \r\n<span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">input<\/span> <span class=\"hljs-attr\">type<\/span>=<span class=\"hljs-string\">\"submit\"<\/span> <span class=\"hljs-attr\">value<\/span>=<span class=\"hljs-string\">\"register\"<\/span>&gt;<\/span>  \r\n<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">form<\/span>&gt;<\/span>  \r\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-7\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">HTML, XML<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">xml<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>19. <strong>What is this keyword in JavaScript?<\/strong><\/p>\n\n\n\n<p>The this keyword is a reference variable that refers to the current object. For example:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-8\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\"><span class=\"hljs-keyword\">var<\/span> address=    \r\n{    \r\n<span class=\"hljs-attr\">company<\/span>:<span class=\"hljs-string\">\"Javatpoint\"<\/span>,    \r\n<span class=\"hljs-attr\">city<\/span>:<span class=\"hljs-string\">\"Noida\"<\/span>,    \r\n<span class=\"hljs-attr\">state<\/span>:<span class=\"hljs-string\">\"UP\"<\/span>,    \r\n<span class=\"hljs-attr\">fullAddress<\/span>:<span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span>(<span class=\"hljs-params\"><\/span>)    \r\n<\/span>{    \r\n<span class=\"hljs-keyword\">return<\/span> <span class=\"hljs-keyword\">this<\/span>.company+<span class=\"hljs-string\">\" \"<\/span>+<span class=\"hljs-keyword\">this<\/span>.city+<span class=\"hljs-string\">\" \"<\/span>+<span class=\"hljs-keyword\">this<\/span>.state;    \r\n}    \r\n};    \r\n<span class=\"hljs-keyword\">var<\/span> fetch=address.fullAddress();    \r\n<span class=\"hljs-built_in\">document<\/span>.writeln(fetch);  \r\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-8\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>20. <strong>How can I remove a specific item from an array?<\/strong><\/p>\n\n\n\n<p>The splice() method changes the contents of an array by removing existing elements and\/or adding new elements.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-9\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-keyword\">const<\/span> <span class=\"hljs-keyword\">array<\/span> = &#91;<span class=\"hljs-number\">2<\/span>, <span class=\"hljs-number\">5<\/span>, <span class=\"hljs-number\">9<\/span>];\r\n\r\nconsole.log(<span class=\"hljs-keyword\">array<\/span>);\r\n\r\n<span class=\"hljs-keyword\">const<\/span> index = <span class=\"hljs-keyword\">array<\/span>.indexOf(<span class=\"hljs-number\">5<\/span>);\r\n<span class=\"hljs-keyword\">if<\/span> (index &gt; <span class=\"hljs-number\">-1<\/span>) {\r\n  <span class=\"hljs-keyword\">array<\/span>.splice(index, <span class=\"hljs-number\">1<\/span>); <span class=\"hljs-comment\">\/\/ 2nd parameter means remove one item only<\/span>\r\n}\r\n\r\n<span class=\"hljs-comment\">\/\/ array = &#91;2, 9]<\/span>\r\nconsole.log(<span class=\"hljs-keyword\">array<\/span>); \r\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-9\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>The second parameter of splice is the number of elements to remove. Note that splice modifies the array in place and returns a new array containing the elements that have been removed.<\/p>\n\n\n\n<p>For the reason of completeness, here are functions. The first function removes only a single occurrence (i.e. removing the first match of 5 from [2,5,9,1,5,8,5]), while the second function removes all occurrences:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-10\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\"><span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> <span class=\"hljs-title\">removeItemOnce<\/span>(<span class=\"hljs-params\">arr, value<\/span>) <\/span>{\r\n  <span class=\"hljs-keyword\">var<\/span> index = arr.indexOf(value);\r\n  <span class=\"hljs-keyword\">if<\/span> (index &gt; <span class=\"hljs-number\">-1<\/span>) {\r\n    arr.splice(index, <span class=\"hljs-number\">1<\/span>);\r\n  }\r\n  <span class=\"hljs-keyword\">return<\/span> arr;\r\n}\r\n\r\n<span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> <span class=\"hljs-title\">removeItemAll<\/span>(<span class=\"hljs-params\">arr, value<\/span>) <\/span>{\r\n  <span class=\"hljs-keyword\">var<\/span> i = <span class=\"hljs-number\">0<\/span>;\r\n  <span class=\"hljs-keyword\">while<\/span> (i &lt; arr.length) {\r\n    <span class=\"hljs-keyword\">if<\/span> (arr&#91;i] === value) {\r\n      arr.splice(i, <span class=\"hljs-number\">1<\/span>);\r\n    } <span class=\"hljs-keyword\">else<\/span> {\r\n      ++i;\r\n    }\r\n  }\r\n  <span class=\"hljs-keyword\">return<\/span> arr;\r\n}\r\n<span class=\"hljs-comment\">\/\/ Usage<\/span>\r\n<span class=\"hljs-built_in\">console<\/span>.log(removeItemOnce(&#91;<span class=\"hljs-number\">2<\/span>,<span class=\"hljs-number\">5<\/span>,<span class=\"hljs-number\">9<\/span>,<span class=\"hljs-number\">1<\/span>,<span class=\"hljs-number\">5<\/span>,<span class=\"hljs-number\">8<\/span>,<span class=\"hljs-number\">5<\/span>], <span class=\"hljs-number\">5<\/span>))\r\n<span class=\"hljs-built_in\">console<\/span>.log(removeItemAll(&#91;<span class=\"hljs-number\">2<\/span>,<span class=\"hljs-number\">5<\/span>,<span class=\"hljs-number\">9<\/span>,<span class=\"hljs-number\">1<\/span>,<span class=\"hljs-number\">5<\/span>,<span class=\"hljs-number\">8<\/span>,<span class=\"hljs-number\">5<\/span>], <span class=\"hljs-number\">5<\/span>))\r\n\r\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-10\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>21. <strong>Could you enumerate the various features of JavaScript?<\/strong><\/p>\n\n\n\n<p>Some important features of JavaScript are:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>A lightweight interpreted a programming language with some object-oriented capabilities.<\/li><li>An open, cross-platform scripting language<\/li><li>Complements and integrates with the Java programming language as well as other backend technologies.<\/li><li>Designed especially for creating network-centric applications <\/li><\/ul>\n\n\n\n<p>22. <strong>Can you differentiate between let and var?<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"463\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/02\/RdERw-1024x463.jpg\" alt=\"\" class=\"wp-image-26421\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/02\/RdERw-1024x463.jpg 1024w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/02\/RdERw-300x136.jpg 300w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/02\/RdERw-768x348.jpg 768w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/02\/RdERw-1536x695.jpg 1536w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2022\/02\/RdERw.jpg 1918w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Both let and var are used for variable and method declaration in JavaScript. However, the most important difference between the two JS keywords is that while the var keyword is function scoped, the let keyword is block scoped.<\/p>\n\n\n\n<p>23. <strong>What are the escape characters in JavaScript?<\/strong><\/p>\n\n\n\n<p><strong>&nbsp;<\/strong>In JavaScript, we use escape characters, typically backslash (\\ \\) while working with special characters, such as ampersands (&amp;), apostrophes (\u2018), double quotes (\u201c \u201c), and single quotes (\u2018 \u2018). Whatever enclosed within the escape, characters get displayed by the JavaScript.<\/p>\n\n\n\n<p>Six additional escape characters are also available in JavaScript:<\/p>\n\n\n\n<p><strong>\\b \u2013 Backspace<\/strong><\/p>\n\n\n\n<p><strong>\\f \u2013 Form feed<\/strong><\/p>\n\n\n\n<p><strong>\\n \u2013 Newline<\/strong><\/p>\n\n\n\n<p><strong>\\r \u2013 Carriage return<\/strong><\/p>\n\n\n\n<p><strong>\\t \u2013 Horizontal tabulator<\/strong><\/p>\n\n\n\n<p><strong>\\v \u2013 Vertical tabulator<\/strong><\/p>\n\n\n\n<p>These aren\u2019t in anyway executed in the HTML or JS code. These were originally designed for controlling fax machines, teletypes, and typewriters.<\/p>\n\n\n\n<p>24. <strong>Please describe the most important advantages of using JavaScript?<\/strong><\/p>\n\n\n\n<p>There are several advantages to using JavaScript. Most notable amongst them are listed down as follows:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Enhanced interactivity \u2013 JavaScript allows creating interfaces that react when the user activates them via the keyboard or merely hovers the cursor over the same.<\/li><li>Immediate feedback \u2013 Visitors need not wait for a page reload to see if they had forgotten to enter some important details.<\/li><li>Low server interaction \u2013 JS allows validating user input before sending the webpage to the server. It means less server traffic and hence, less load on the server.<\/li><li>Rich interfaces \u2013 JS has items like drag-and-drop components and sliders to present a richer interface to the website visitors.<\/li><\/ul>\n\n\n\n<p>25. <strong>What are the different types of Error Name values in JavaScript?<\/strong><\/p>\n\n\n\n<p>There are 6 types of Error Name values. Each one of them is briefly explained as follows:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Eval Error \u2013 Thrown when coming across an error in eval() (Newer JS releases don\u2019t have it)<\/li><li>Range Error \u2013 Generated when a number outside the specified range is used<\/li><li>Reference Error \u2013 It comes into play when an undeclared variable is used.<\/li><li>Syntax Error \u2013 When the incorrect syntax is used, we get this error<\/li><li>Type Error \u2013 This error is thrown when a value outside the range of data types is tried to be used.<\/li><li>URI Error \u2013 Generated due to the use of illegal characters<\/li><\/ul>\n\n\n\n<p>26. <strong>Explain the difference between function declaration and function expression?<\/strong><\/p>\n\n\n\n<p>Following are the differences between function declaration and function expression:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Definition \u2013 A function declared as a separate statement in the main code flow is termed the function declaration. When a function is created inside an expression or another syntax construct, it is called a function expression.<\/li><li>Strict Mode \u2013 When a function declaration is within a code block in the Strict mode, it is visible everywhere inside that block but not outside of it. This isn\u2019t the case for a function expression.<\/li><li>Time of Use \u2013 A function expression is created when the execution reaches it. The function expression is usable only from that moment onwards. A function declaration, on the other hand, can be called before the same is defined.<\/li><li>When to Use \u2013 Function declaration offers better readability and offers more freedom in organizing the code. Function expressions are typically restricted to be used when there is a need for a conditional declaration. <\/li><\/ul>\n\n\n\n<p>27. <strong>What are the various ways of embedding JavaScript code in an HTML file?<\/strong><\/p>\n\n\n\n<p>There are 4 ways of embedding JS code within HTML documents:<\/p>\n\n\n\n<p>Adding it between tags From an external file that is specified by the src attribute of a tag. Old browsers treat this JS code as a long HTML comment.<\/p>\n\n\n\n<p>Typically, JS code is hidden from old browsers for solving compatibility and UI issues. Interestingly, browsers that support JavaScript will take as one-line comments.<\/p>\n\n\n\n<p>28. <strong>Explain event bubbling and how one may prevent it<\/strong><\/p>\n\n\n\n<p>Event bubbling is the concept in which an event triggers at the deepest possible element, and triggers on parent elements in nesting order. As a result, when clicking on a child element one may exhibit the handler of the parent activating.<\/p>\n\n\n\n<p>One way to prevent event bubbling is using<strong> event.stopPropagation() or event.cancelBubble on IE &lt; <\/strong><\/p>\n\n\n\n<p><strong>29. What is let keyword in JavaScript?<\/strong><\/p>\n\n\n\n<p>In addition to creating declarations for variables at the function level, ES6 lets you declare variables to belong to individual blocks (pairs of { .. }), using the let keyword.<\/p>\n\n\n\n<p>30. <strong>What is IIFEs (Immediately Invoked Function Expressions)?<\/strong><\/p>\n\n\n\n<p>It\u2019s an Immediately-Invoked Function Expression, or IIFE for short. It executes immediately after it\u2019s created:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-11\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">(<span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> <span class=\"hljs-title\">IIFE<\/span>(<span class=\"hljs-params\"><\/span>)<\/span>{\r\n    <span class=\"hljs-built_in\">console<\/span>.log( <span class=\"hljs-string\">\"Hello!\"<\/span> );\r\n})();\r\n<span class=\"hljs-comment\">\/\/ \"Hello!\"<\/span>\r\n\nThis pattern is often used when trying to avoid polluting the global namespace, because all the variables used inside the IIFE (like <span class=\"hljs-keyword\">in<\/span> any other normal <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span>) <span class=\"hljs-title\">are<\/span> <span class=\"hljs-title\">not<\/span> <span class=\"hljs-title\">visible<\/span> <span class=\"hljs-title\">outside<\/span> <span class=\"hljs-title\">its<\/span> <span class=\"hljs-title\">scope<\/span>.\n<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-11\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>31. <strong>How to compare two objects in JavaScript?<\/strong><\/p>\n\n\n\n<p>Two non-primitive values, like objects (including function and array) held by reference, so both == and === comparisons will simply check whether the references match, not anything about the underlying values.<\/p>\n\n\n\n<p>For example, arrays are by default coerced to strings by simply joining all the values with commas (,) in between. So two arrays with the same contents would not be == equal:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-12\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\"><span class=\"hljs-keyword\">var<\/span> a = &#91;<span class=\"hljs-number\">1<\/span>,<span class=\"hljs-number\">2<\/span>,<span class=\"hljs-number\">3<\/span>];\r\n<span class=\"hljs-keyword\">var<\/span> b = &#91;<span class=\"hljs-number\">1<\/span>,<span class=\"hljs-number\">2<\/span>,<span class=\"hljs-number\">3<\/span>];\r\n<span class=\"hljs-keyword\">var<\/span> c = <span class=\"hljs-string\">\"1,2,3\"<\/span>;\r\n\r\na == c;     <span class=\"hljs-comment\">\/\/ true<\/span>\r\nb == c;     <span class=\"hljs-comment\">\/\/ true<\/span>\r\na == b;     <span class=\"hljs-comment\">\/\/ false<\/span>\r\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-12\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>32. <strong>Could you explain the difference between ES5 and ES6<\/strong><\/p>\n\n\n\n<p>ECMAScript 5 (ES5): The 5th edition of ECMAScript, standardized in 2009. This standard has been implemented fairly completely in all modern browsers<\/p>\n\n\n\n<p>ECMAScript 6 (ES6)\/ ECMAScript 2015 (ES2015): The 6th edition of ECMAScript, standardized in 2015. This standard has been partially implemented in most modern browsers.<\/p>\n\n\n\n<p>Here are some key differences between ES5 and ES6:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-13\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">Arrow functions &amp; string interpolation: Consider:\r\n<span class=\"hljs-keyword\">const<\/span> greetings = <span class=\"hljs-function\">(<span class=\"hljs-params\">name<\/span>) =&gt;<\/span> {\r\n      <span class=\"hljs-keyword\">return<\/span> <span class=\"hljs-string\">`hello <span class=\"hljs-subst\">${name}<\/span>`<\/span>;\r\n}\r\nand even:\r\n<span class=\"hljs-keyword\">const<\/span> greetings = <span class=\"hljs-function\"><span class=\"hljs-params\">name<\/span> =&gt;<\/span> <span class=\"hljs-string\">`hello <span class=\"hljs-subst\">${name}<\/span>`<\/span>;\r\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-13\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Const. Const works like a constant in other languages in many ways but there are some caveats. Const stands for \u2018constant reference\u2019 to a value. So with const, you can actually mutate the properties of an object being referenced by the variable. You just can\u2019t change the reference itself.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-14\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\"><span class=\"hljs-keyword\">const<\/span> NAMES = &#91;];\r\nNAMES.push(<span class=\"hljs-string\">\"Jim\"<\/span>);\r\n<span class=\"hljs-built_in\">console<\/span>.log(NAMES.length === <span class=\"hljs-number\">1<\/span>); <span class=\"hljs-comment\">\/\/ true<\/span>\r\nNAMES = &#91;<span class=\"hljs-string\">\"Steve\"<\/span>, <span class=\"hljs-string\">\"John\"<\/span>]; <span class=\"hljs-comment\">\/\/ error<\/span>\r\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-14\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Block-scoped variables. The new ES6 keyword let allows developers to scope variables at the block level. Let doesn\u2019t hoist in the same way var does.<\/p>\n\n\n\n<p>Default parameter values Default parameters allow us to initialize functions with default values. A default is used when an argument is either omitted or undefined \u2014 meaning null is a valid value.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-15\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\"><span class=\"hljs-comment\">\/\/ Basic syntax<\/span>\r\n<span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> <span class=\"hljs-title\">multiply<\/span> (<span class=\"hljs-params\">a, b = <span class=\"hljs-number\">2<\/span><\/span>) <\/span>{\r\n     <span class=\"hljs-keyword\">return<\/span> a * b;\r\n}\r\nmultiply(<span class=\"hljs-number\">5<\/span>); <span class=\"hljs-comment\">\/\/ 10<\/span>\r\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-15\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Class Definition and Inheritance<\/p>\n\n\n\n<p>ES6 introduces language support for classes (class keyword), constructors (constructor keyword), and the extend keyword for inheritance.<\/p>\n\n\n\n<p>for-of operator<\/p>\n\n\n\n<p>The for&#8230;of statement creates a loop iterating over iterable objects.<\/p>\n\n\n\n<p>Spread Operator<\/p>\n\n\n\n<p>For objects merging<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-16\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\"><span class=\"hljs-keyword\">const<\/span> obj1 = { <span class=\"hljs-attr\">a<\/span>: <span class=\"hljs-number\">1<\/span>, <span class=\"hljs-attr\">b<\/span>: <span class=\"hljs-number\">2<\/span> }\r\n<span class=\"hljs-keyword\">const<\/span> obj2 = { <span class=\"hljs-attr\">a<\/span>: <span class=\"hljs-number\">2<\/span>, <span class=\"hljs-attr\">c<\/span>: <span class=\"hljs-number\">3<\/span>, <span class=\"hljs-attr\">d<\/span>: <span class=\"hljs-number\">4<\/span>}\r\n<span class=\"hljs-keyword\">const<\/span> obj3 = {...obj1, ...obj2}\r\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-16\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Promises Promises provide a mechanism to handle the results and errors from asynchronous operations. You can accomplish the same thing with callbacks, but promises provide improved readability via method chaining and succinct error handling.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-17\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\"><span class=\"hljs-keyword\">const<\/span> isGreater = <span class=\"hljs-function\">(<span class=\"hljs-params\">a, b<\/span>) =&gt;<\/span> {\r\n  <span class=\"hljs-keyword\">return<\/span> <span class=\"hljs-keyword\">new<\/span> <span class=\"hljs-built_in\">Promise<\/span> (<span class=\"hljs-function\">(<span class=\"hljs-params\">resolve, reject<\/span>) =&gt;<\/span> {\r\n    <span class=\"hljs-keyword\">if<\/span>(a &gt; b) {\r\n      resolve(<span class=\"hljs-literal\">true<\/span>)\r\n    } <span class=\"hljs-keyword\">else<\/span> {\r\n      reject(<span class=\"hljs-literal\">false<\/span>)\r\n    }\r\n    })\r\n}\r\nisGreater(<span class=\"hljs-number\">1<\/span>, <span class=\"hljs-number\">2<\/span>)\r\n  .then(<span class=\"hljs-function\"><span class=\"hljs-params\">result<\/span> =&gt;<\/span> {\r\n    <span class=\"hljs-built_in\">console<\/span>.log(<span class=\"hljs-string\">'greater'<\/span>)\r\n  })\r\n .catch(<span class=\"hljs-function\"><span class=\"hljs-params\">result<\/span> =&gt;<\/span> {\r\n    <span class=\"hljs-built_in\">console<\/span>.log(<span class=\"hljs-string\">'smaller'<\/span>)\r\n })\r\nModules exporting &amp; importing Consider <span class=\"hljs-built_in\">module<\/span> exporting:\r\n<span class=\"hljs-keyword\">const<\/span> myModule = { <span class=\"hljs-attr\">x<\/span>: <span class=\"hljs-number\">1<\/span>, <span class=\"hljs-attr\">y<\/span>: <span class=\"hljs-function\"><span class=\"hljs-params\">()<\/span> =&gt;<\/span> { <span class=\"hljs-built_in\">console<\/span>.log(<span class=\"hljs-string\">'This is ES5'<\/span>) }}\r\n<span class=\"hljs-keyword\">export<\/span> <span class=\"hljs-keyword\">default<\/span> myModule;\r\nand importing:\r\n<span class=\"hljs-keyword\">import<\/span> myModule <span class=\"hljs-keyword\">from<\/span> <span class=\"hljs-string\">'.\/myModule'<\/span>;\r\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-17\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>34. <strong>What is the difference between anonymous and named functions?<\/strong><\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-18\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\"><span class=\"hljs-keyword\">var<\/span> foo = <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span>(<span class=\"hljs-params\"><\/span>) <\/span>{ <span class=\"hljs-comment\">\/\/ anonymous function assigned to variable foo<\/span>\r\n    <span class=\"hljs-comment\">\/\/ ..<\/span>\r\n};\r\n\r\n<span class=\"hljs-keyword\">var<\/span> x = <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> <span class=\"hljs-title\">bar<\/span>(<span class=\"hljs-params\"><\/span>)<\/span>{ <span class=\"hljs-comment\">\/\/ named function (bar) assigned to variable x <\/span>\r\n    <span class=\"hljs-comment\">\/\/ ..<\/span>\r\n};\r\n\r\nfoo(); <span class=\"hljs-comment\">\/\/ actual function execution<\/span>\r\nx();\r\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-18\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>35. <strong>What is the use of a Set object in JavaScript?<\/strong><\/p>\n\n\n\n<p>The JavaScript Set object is used to store the elements with unique values. The values can be of any type i.e. whether primitive values or object references. For example:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-19\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\"><span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> <span class=\"hljs-title\">display<\/span>(<span class=\"hljs-params\"><\/span>)  \r\n<\/span>{  \r\n<span class=\"hljs-keyword\">var<\/span> <span class=\"hljs-keyword\">set<\/span> = new Set();    \r\n<span class=\"hljs-keyword\">set<\/span>.add(\"jQuery\");    \r\n<span class=\"hljs-keyword\">set<\/span>.add(\"AngularJS\");    \r\n<span class=\"hljs-keyword\">set<\/span>.add(\"Bootstrap\");    \r\nfor (let elements of <span class=\"hljs-keyword\">set<\/span>) {    \r\n <span class=\"hljs-built_in\">document<\/span>.writeln(elements+<span class=\"hljs-string\">\"&lt;br&gt;\"<\/span>);    \r\n}     \r\n}  \r\ndisplay();  \r\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-19\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>36. <strong>What is the use of a WeakSet object in JavaScript?<\/strong><\/p>\n\n\n\n<p>The JavaScript WeakSet object is the type of collection that allows us to store weakly held objects. Unlike Set, the WeakSet are the collections of objects only. It doesn&#8217;t contain the arbitrary values. For example:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-20\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\"><span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> <span class=\"hljs-title\">display<\/span>(<span class=\"hljs-params\"><\/span>)  \r\n<\/span>{  \r\n<span class=\"hljs-keyword\">var<\/span> ws = <span class=\"hljs-keyword\">new<\/span> <span class=\"hljs-built_in\">WeakSet<\/span>();    \r\n<span class=\"hljs-keyword\">var<\/span> obj1={};    \r\n<span class=\"hljs-keyword\">var<\/span> obj2={};    \r\nws.add(obj1);    \r\nws.add(obj2);    \r\n<span class=\"hljs-comment\">\/\/Let's check whether the WeakSet object contains the added object    <\/span>\r\n<span class=\"hljs-built_in\">document<\/span>.writeln(ws.has(obj1)+<span class=\"hljs-string\">\"&lt;br&gt;\"<\/span>);    \r\n<span class=\"hljs-built_in\">document<\/span>.writeln(ws.has(obj2));     \r\n}     \r\ndisplay()  \r\n\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-20\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>37. <strong>What is the use of a Map object in JavaScript?<\/strong><\/p>\n\n\n\n<p>The JavaScript Map object is used to map keys to values. It stores each element as key-value pair. It operates the elements such as search, update and delete on the basis of specified key. For example:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-21\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\"><span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> <span class=\"hljs-title\">display<\/span>(<span class=\"hljs-params\"><\/span>)  \r\n<\/span>{  \r\n<span class=\"hljs-keyword\">var<\/span> wm = <span class=\"hljs-keyword\">new<\/span> <span class=\"hljs-built_in\">WeakMap<\/span>();    \r\n<span class=\"hljs-keyword\">var<\/span> obj1 = {};    \r\n<span class=\"hljs-keyword\">var<\/span> obj2 = {};    \r\n<span class=\"hljs-keyword\">var<\/span> obj3= {};    \r\nwm.set(obj1, <span class=\"hljs-string\">\"jQuery\"<\/span>);    \r\nwm.set(obj2, <span class=\"hljs-string\">\"AngularJS\"<\/span>);    \r\nwm.set(obj3,<span class=\"hljs-string\">\"Bootstrap\"<\/span>);    \r\n<span class=\"hljs-built_in\">document<\/span>.writeln(wm.has(obj2));     \r\n}     \r\ndisplay();  \r\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-21\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>38. <strong>What are the false values in JavaScript, and how can we check if a value is falsy?<\/strong><\/p>\n\n\n\n<p>Those values which become false while converting to Boolean are called falsy values<strong>.<\/strong><\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-22\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\"><span class=\"hljs-keyword\">const<\/span> falsyValues = &#91;<span class=\"hljs-string\">''<\/span>, <span class=\"hljs-number\">0<\/span>, <span class=\"hljs-literal\">null<\/span>, <span class=\"hljs-literal\">undefined<\/span>, <span class=\"hljs-literal\">NaN<\/span>, <span class=\"hljs-literal\">false<\/span>];   <\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-22\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>39. <strong>What do you understand by hoisting in JavaScript?<\/strong><\/p>\n\n\n\n<p>Hoisting is the default behavior of JavaScript where all the variable and function declarations are moved on top. In simple words, we can say that Hoisting is a process in which, irrespective of where the variables and functions are declared, they are moved on top of the scope. The scope can be both local and global.<\/p>\n\n\n\n<p>40. <strong>What is BOM?<\/strong><\/p>\n\n\n\n<p>BOM stands for Browser Object Model. It provides interaction with the browser. The default object of a browser is a window. So, you can call all the functions of the window by specifying the window or directly. The window object provides various properties like document, history, screen, navigator, location, innerHeight, innerWidth,<\/p>\n\n\n\n<p>41. <strong>What is DOM? What is the use of document object?<\/strong><\/p>\n\n\n\n<p>DOM stands for Document Object Model. A document object represents the HTML document. It can be used to access and change the content of HTML.<\/p>\n\n\n\n<p>More Details: Document Object Model<\/p>\n\n\n\n<p>42. <strong>What is the use of window object?<\/strong><\/p>\n\n\n\n<p>The window object is created automatically by the browser that represents a window of a browser. It is not an object of JavaScript. It is a browser object.<\/p>\n\n\n\n<p>43. <strong>What is the use of history object?<\/strong><\/p>\n\n\n\n<p>The history object of a browser can be used to switch to history pages such as back and forward from the current page or another page. There are three methods of history object.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-23\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css\"><span class=\"hljs-selector-tag\">history<\/span><span class=\"hljs-selector-class\">.back<\/span>() <span class=\"hljs-selector-tag\">-<\/span> <span class=\"hljs-selector-tag\">It<\/span> <span class=\"hljs-selector-tag\">loads<\/span> <span class=\"hljs-selector-tag\">the<\/span> <span class=\"hljs-selector-tag\">previous<\/span> <span class=\"hljs-selector-tag\">page<\/span>.\r\n<span class=\"hljs-selector-tag\">history<\/span><span class=\"hljs-selector-class\">.forward<\/span>() <span class=\"hljs-selector-tag\">-<\/span> <span class=\"hljs-selector-tag\">It<\/span> <span class=\"hljs-selector-tag\">loads<\/span> <span class=\"hljs-selector-tag\">the<\/span> <span class=\"hljs-selector-tag\">next<\/span> <span class=\"hljs-selector-tag\">page<\/span>.\r\n<span class=\"hljs-selector-tag\">history<\/span><span class=\"hljs-selector-class\">.go<\/span>(<span class=\"hljs-selector-tag\">number<\/span>) <span class=\"hljs-selector-tag\">-<\/span> <span class=\"hljs-selector-tag\">The<\/span> <span class=\"hljs-selector-tag\">number<\/span> <span class=\"hljs-selector-tag\">may<\/span> <span class=\"hljs-selector-tag\">be<\/span> <span class=\"hljs-selector-tag\">positive<\/span> <span class=\"hljs-selector-tag\">for<\/span> <span class=\"hljs-selector-tag\">forward<\/span>, <span class=\"hljs-selector-tag\">negative<\/span> <span class=\"hljs-selector-tag\">for<\/span> <span class=\"hljs-selector-tag\">backward<\/span>. <span class=\"hljs-selector-tag\">It<\/span> <span class=\"hljs-selector-tag\">loads<\/span> <span class=\"hljs-selector-tag\">the<\/span> <span class=\"hljs-selector-tag\">given<\/span> <span class=\"hljs-selector-tag\">page<\/span> <span class=\"hljs-selector-tag\">number<\/span>.\r\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-23\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>44. <strong>How to write a comment in JavaScript?<\/strong><\/p>\n\n\n\n<p>There are two types of comments in JavaScript<strong>.<\/strong><\/p>\n\n\n\n<p><strong>Single Line Comment: It is represented by \/\/ (double forward slash)<\/strong><\/p>\n\n\n\n<p><strong>Multi-Line Comment: Slash represents it with asterisk symbol as \/* write comment here *\/<\/strong><\/p>\n\n\n\n<p><strong>What are the different data types present in JavaScript?<\/strong><\/p>\n\n\n\n<p>There are two types of data types in JavaScript:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Primitive data types<\/li><li>Non- Primitive data types<\/li><li>Primitive data types<\/li><\/ul>\n\n\n\n<p>The primitive data types are as follows:<\/p>\n\n\n\n<p>String: The string data type represents a sequence of characters. It is written within quotes and can be represented using a single or a double quote.<\/p>\n\n\n\n<p>Example:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-24\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\"><span class=\"hljs-keyword\">var<\/span> str1 = <span class=\"hljs-string\">\"Hello JavaTpoint\"<\/span>; <span class=\"hljs-comment\">\/\/using double quotes  <\/span>\r\n<span class=\"hljs-keyword\">var<\/span> str2 = <span class=\"hljs-string\">'Hello Javatpoint'<\/span>; <span class=\"hljs-comment\">\/\/using single quotes  <\/span>\r\n<span class=\"hljs-built_in\">Number<\/span>: The number data type is used to represent numeric values and can be written <span class=\"hljs-keyword\">with<\/span> or without decimals.\r\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-24\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Example:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-25\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\"><span class=\"hljs-keyword\">var<\/span> x = <span class=\"hljs-number\">5<\/span>; <span class=\"hljs-comment\">\/\/without decimal  <\/span>\r\n<span class=\"hljs-keyword\">var<\/span> y = <span class=\"hljs-number\">5.0<\/span>; <span class=\"hljs-comment\">\/\/with decimal  <\/span>\r\n<span class=\"hljs-built_in\">Boolean<\/span>: The <span class=\"hljs-built_in\">Boolean<\/span> data type is used to represent a <span class=\"hljs-built_in\">Boolean<\/span> value, either <span class=\"hljs-literal\">false<\/span> or <span class=\"hljs-literal\">true<\/span>. This data type is generally used <span class=\"hljs-keyword\">for<\/span> conditional testing.<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-25\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Example:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-26\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\"><span class=\"hljs-keyword\">var<\/span> x = <span class=\"hljs-number\">5<\/span>;  \r\n<span class=\"hljs-keyword\">var<\/span> y =  <span class=\"hljs-number\">6<\/span>;  \r\n<span class=\"hljs-keyword\">var<\/span> z =  <span class=\"hljs-number\">5<\/span>;  \r\n(x == y) <span class=\"hljs-comment\">\/\/ returns false  <\/span>\r\n(x == z) <span class=\"hljs-comment\">\/\/returns true  <\/span>\r\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-26\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>45. <strong>What is the procedure to merge two arrays?<\/strong><\/p>\n\n\n\n<p>Ans. Syntax:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-27\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\"><span class=\"hljs-keyword\">var<\/span> arr1 = &#91;<span class=\"hljs-number\">1<\/span>,<span class=\"hljs-number\">2<\/span>,<span class=\"hljs-number\">3<\/span>]\r\n\r\n<span class=\"hljs-keyword\">var<\/span> arr2 = &#91;<span class=\"hljs-number\">4<\/span>,<span class=\"hljs-number\">5<\/span>,<span class=\"hljs-number\">6<\/span>,<span class=\"hljs-number\">7<\/span>]\r\n\r\n<span class=\"hljs-keyword\">var<\/span> mergedArrays = &#91;\u2026arr1, \u2026arr2]\r\n\r\n<span class=\"hljs-built_in\">document<\/span>.write(\u2018Merged arrays\u2019, mergedArrays)\r\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-27\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>46. <strong>Explain Loops in JavaScript.<\/strong><\/p>\n\n\n\n<p>Ans. In JavaScript, Loops are used to execute a block of code repeatedly. Loops offer a quick and easy way to repeat an action. They execute the same lines of code a specific number of times or as long as a specific condition is true. JavaScript supports the following types of loops:<\/p>\n\n\n\n<p><strong>1. for loop: loops through a block of code a number of times<\/strong><\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-28\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">Syntax:\r\n\r\n<span class=\"hljs-keyword\">for<\/span>(statement1; statement2; statment3)\r\n\r\n{\r\n\r\nlines of code to be executed\r\n\r\n}\r\n\r\n<span class=\"hljs-number\">2.<\/span> <span class=\"hljs-keyword\">for<\/span>-in loop: It is used to loop the object through properties.\r\n\r\nSyntax:\r\n\r\n<span class=\"hljs-keyword\">for<\/span> (variablename in objectname)\r\n\r\n{\r\n\r\nlines of code to be executed\r\n\r\n}\r\n\r\n<span class=\"hljs-number\">3.<\/span> <span class=\"hljs-keyword\">while<\/span> loop: loops through a block of code <span class=\"hljs-keyword\">while<\/span> a specified condition is <span class=\"hljs-keyword\">true<\/span>.\r\n\r\nSyntax:\r\n\r\n<span class=\"hljs-keyword\">while<\/span>(condition)\r\n\r\n{\r\n\r\nlines of code to be executed\r\n\r\n}\r\n\r\n<span class=\"hljs-number\">4.<\/span> <span class=\"hljs-keyword\">do<\/span>\/<span class=\"hljs-keyword\">while<\/span> loop: loops through a block of code <span class=\"hljs-keyword\">while<\/span> a specified condition is <span class=\"hljs-keyword\">true<\/span>. It is similar to the <span class=\"hljs-keyword\">while<\/span> loop. The only difference is that in the <span class=\"hljs-keyword\">do<\/span>\/<span class=\"hljs-keyword\">while<\/span> loop, the block of code gets executed once even before checking the condition.\r\n\r\nSyntax:\r\n\r\n&lt;pre&gt;\r\n\r\n<span class=\"hljs-keyword\">do<\/span>\r\n\r\n{\r\n\r\nblock of code to be executed\r\n\r\n} <span class=\"hljs-keyword\">while<\/span> (condition)\r\n\r\n\r\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-28\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>47. <strong>How do we target a particular frame from a hyperlink?<\/strong><\/p>\n\n\n\n<p><strong>Ans<\/strong>.\u00a0 We can target a particular frame from a hyperlink by consisting the name of the required frame and can use \u2018target\u2019 attribute in it.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-29\" data-shcb-language-name=\"HTML, XML\" data-shcb-language-slug=\"xml\"><span><code class=\"hljs language-xml\"><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">a<\/span> <span class=\"hljs-attr\">href<\/span>=<span class=\"hljs-string\">\u201d\/newpage.htm\u201d<\/span> <span class=\"hljs-attr\">target<\/span>=<span class=\"hljs-string\">\u201dnewframe\u201d<\/span>&gt;<\/span>&gt;New Page<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">a<\/span>&gt;<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-29\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">HTML, XML<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">xml<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p><strong>48.  Name the method we can use to read and write a file in JavaScript?<\/strong><\/p>\n\n\n\n<p><strong>Ans. <\/strong>JavaScript extensions can be used to read and write a file such as for opening of a file \u2013<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">fh = fopen(getScriptPath(), 0);\n<\/code><\/span><\/pre>\n\n\n<p>49. <strong>Explain what are Screen objects?<\/strong><\/p>\n\n\n\n<p><strong>Ans. <\/strong>Screen objects hold information from the client\u2019s screen. It is also used to display screen width, pixelDepth, height, etc. Let\u2019s look at the properties of screen objects-<\/p>\n\n\n\n<p>AvailWidth: Provides the width of the client\u2019s screen<\/p>\n\n\n\n<p>AvailHeight: Provides the height of the client\u2019s screen<\/p>\n\n\n\n<p>ColorDepth: Provides the bit depth of images on the client\u2019s screen<\/p>\n\n\n\n<p>Width: Provides the total width of the client\u2019s screen, including the taskbar<\/p>\n\n\n\n<p>Height: Provides the total height of the client\u2019s screen, including the taskbar<\/p>\n\n\n\n<p>Explore the Top Universities Offering Free Online Programming Courses<\/p>\n\n\n\n<p><strong> 50. What does the below-given statement specify?<\/strong><\/p>\n\n\n\n<p><strong>Ans. <\/strong>var myArray = [[[]]];<\/p>\n\n\n\n<p>It specifies a three-dimensional array.<\/p>\n\n\n\n<p>51. <strong>What syntax we can use to hide JavaScript codes from old browsers that don\u2019t support JavaScript?<\/strong><\/p>\n\n\n\n<p><strong>Ans. <\/strong>We can use given codes for hiding JavaScript codes from old browsers:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-30\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">Use \u201c&lt;!\u2013\u201d without the quotes <span class=\"hljs-keyword\">in<\/span> the code after the &lt;script&gt; tag.\r\n\r\nUse \u201c<span class=\"hljs-comment\">\/\/\u2013&gt;\u201d without the quotes in the code before the &lt;script&gt; tag.<\/span>\r\nThese codes are not treated by old browsers whereas a browser that supports JavaScript, it will take the \u201c&lt;!\u2013\u201d and \u201c<span class=\"hljs-comment\">\/\/\u2013&gt;\u201d as one-line comments.<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-30\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p><strong>So, here I m ending this question and answer series. I hope this series would help you. If you are candidate who is willing to learn JavaScript and wants to become a JavaScript developer, then enroll and get certified from DevOpsSchool. You may also subscribe to YouTube channel devopsschool and scmgalaxy for more knowledge in DevOps, cloud and containers.<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>JavaScript could be a scripting or artificial language that enables you to implement advanced options on websites each time an internet page will quite simply sit there and show static info for you to seem at displaying timely content updates, interactive maps, animated 2D\/3D graphics, scrolling video jukeboxes, etc. you&#8217;ll be able to bet that&#8230;<\/p>\n","protected":false},"author":1,"featured_media":26414,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"_kad_post_classname":"","_joinchat":[],"footnotes":""},"categories":[5691],"tags":[5449,3310,5611,7177,7175,7179,7178,5491,7174,7173,7180,7176,6284,6289],"class_list":["post-26405","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-javascript","tag-devopsschool","tag-java-system-properties-access-guide","tag-javascript","tag-javascript-advance","tag-javascript-advantages","tag-javascript-course","tag-javascript-for-beginners","tag-javascript-framework","tag-javascript-interview-questions","tag-javascript-questions","tag-javascript-training","tag-javascript-tutorials","tag-javascript-operators","tag-operators-in-javascrip"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/26405","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=26405"}],"version-history":[{"count":2,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/26405\/revisions"}],"predecessor-version":[{"id":26425,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/26405\/revisions\/26425"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media\/26414"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=26405"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=26405"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=26405"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}