avatarDaniel Anderson

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

5179

Abstract

on is true</p><p id="5aea"><code>do/while</code> - also loops through a block of code while a specified condition is true</p><h2 id="dfb5">What is the difference between var , let and const?</h2><p id="3f50"><code>var</code> can be redeclared and updated.</p><p id="2e67"><code>let</code> can be updated but not declared</p><p id="d931"><code>const</code> cannot be updated or redeclared.</p><p id="fb4e"><i>Example:</i></p><div id="53cb"><pre>var myNumber <span class="hljs-operator">=</span> <span class="hljs-number">10</span><span class="hljs-comment">;</span> var myNumber <span class="hljs-operator">=</span> <span class="hljs-number">20</span><span class="hljs-comment">;</span></pre></div><div id="a573"><pre><span class="hljs-comment">// No error</span></pre></div><div id="6e1f"><pre>let myNumber <span class="hljs-operator">=</span> <span class="hljs-number">10</span><span class="hljs-comment">;</span> let myNumber <span class="hljs-operator">=</span> <span class="hljs-number">20</span><span class="hljs-comment">;</span></pre></div><div id="7198"><pre><span class="hljs-comment">// In the console I get an error:</span> <span class="hljs-title class_">Uncaught</span> <span class="hljs-title class_">SyntaxError</span>: <span class="hljs-title class_">Identifier</span> <span class="hljs-string">'myNumber'</span> has already been declared</pre></div><h2 id="9123">What is the difference between NULL and undefined ?</h2><p id="3bcc"><code>NULL</code> is an assignment value. It can be assigned to a variable as a representation of no value.</p><p id="3750"><code>undefined</code> means a variable has been declared but has not yet been assigned a value</p><p id="969e"><i>Example:</i></p><div id="6c54"><pre><span class="hljs-keyword">let</span> hi; <span class="hljs-comment">// undefined</span></pre></div><div id="0c5e"><pre><span class="hljs-keyword">let</span> hi = <span class="hljs-built_in">NULL</span>; <span class="hljs-comment">//NULL</span></pre></div><h2 id="9fe7">What is the typeof operator used for?</h2><p id="ff0b"><code>typeof</code> the operator returns a string indicating the type of the unevaluated operand.</p><p id="9bb1"><i>Example:</i></p><div id="7c82"><pre><span class="hljs-function"><span class="hljs-title">typeof</span><span class="hljs-params">(<span class="hljs-number">122</span>)</span></span> <span class="hljs-comment">// "number"</span> <span class="hljs-function"><span class="hljs-title">typeof</span><span class="hljs-params">(<span class="hljs-number">122.55</span>)</span></span> <span class="hljs-comment">// "number"</span> <span class="hljs-function"><span class="hljs-title">typeof</span><span class="hljs-params">(<span class="hljs-string">"I'm a string"</span>)</span></span> <span class="hljs-comment">// "string"</span> <span class="hljs-function"><span class="hljs-title">typeof</span><span class="hljs-params">({ name: <span class="hljs-string">"James Smith"</span>})</span></span> <span class="hljs-comment">// "object"</span> <span class="hljs-function"><span class="hljs-title">typeof</span><span class="hljs-params">(false)</span></span> <span class="hljs-comment">// "boolean"</span></pre></div><h2 id="4686">How do you check if an object is an array?</h2><p id="9fcd"><code>isArray()</code> function determines whether an object is an array.</p><h2 id="f888">What is a callback?</h2><p id="66b5">A callback function, also known as a higher-order function, is a function that is passed to another function as a parameter.</p><h2 id="8e39">Explain what default function parameters are</h2><p id="a2a9">They allow named parameters to be initialized with default values if no value or <code>undefined</code> is passed.</p><p id="bf06"><i>Example:</i></p><div id="290d"><pre><span class="hljs-keyword">function</span> <span class="hljs-title">addTogether</span>(x, y = 1) { <span class="hljs-keyword">return</span> <span class="hljs-type">x</span> + y; }</pre></div><div id="062e"><pre><span class="hljs-function"><span class="hljs-title">addTogether</span><span class="hljs-params">(<span class="hljs-number">10</span>, <span class="hljs-number">10</span>)</span></span> <span class="hljs-comment">// 20</span> <span class="hljs-function"><span class="hljs-title">addTogether</span><span class="hljs-params">(<span class="hljs-number">10</span>)</span></span> <span class="hljs-comment">// 11</span></pre></div><h2 id="d7ad">What are ES6 modules?</h2><p id="9113">They Organise a related set of JavaScript code. A module can contain variables and functions. A module is nothing more than a chunk of JavaScript code written in a file.</p><h2 id="058b">Name the two different ES6 exports</h2><p id="5ae8"><b>Default</b> exports are used when a module only needs to export only a single value.</p><p id="ed62"><b>Named </b>exports are distinguished by their names. There can be serval named exports in a module.</p><h2 id="bbc6">What are Promises?</h2><p id="d294">They are used to handle asynchronous operations. They can handle multiple asynchronous operations easily and provide better error handling than callbacks and events.</p><h2 id="1519">What are the different states in promises?</h2><p id="384

Options

b">A Promise has three states:</p><ol><li><b>fulfilled</b>: Action related to the promise succeeded</li><li><b>rejected</b>: Action related to the promise failed</li><li><b>pending</b>: Promise is still pending i.e not fulfilled or rejected yet</li></ol><h2 id="ca87">What is async/await?</h2><p id="3ee4"><code>async</code> before a function means one simple thing: a function always returns a promise. Other values are wrapped in a resolved promise automatically.</p><p id="1768"><code>await</code> makes JavaScript wait until that promise settles and returns its result.</p><h2 id="9db4">What is the difference between local storage & session storage?</h2><p id="4bd9"><code>local</code> persists until explicitly deleted. Changes made are saved and available for all current and future visits to the site.</p><p id="881d"><code>session</code> changes are only available per tab. Changes made are saved and available for the current page in that tab until it is closed. Once it is closed, the stored data is deleted.</p><h2 id="bd46">Name the different DOM selectors</h2><ul><li>getElementsByTagName()</li><li>getElementsByClassName()</li><li>getElementById()</li><li>querySelector()</li><li>querySelectorAll()</li></ul><h2 id="af58">What is a closure?</h2><p id="031a">We need closures when a variable which is defined outside the scope in reference is accessed from some inner scope.</p><h2 id="a833">How do you add an item(s) to an array?</h2><p id="2e19">You can use the <code>push()</code> function to append an item to an array. It can also add many items at the same time.</p><p id="4e4a"><i>Example:</i></p><div id="09b2"><pre><span class="hljs-attribute">let items</span> = [<span class="hljs-string">"dan"</span>, <span class="hljs-string">"john"</span>];</pre></div><div id="d616"><pre>items.push(<span class="hljs-string">"liam"</span>); <span class="hljs-regexp">//</span> [<span class="hljs-string">"dan"</span>, <span class="hljs-string">"john"</span>, <span class="hljs-string">"liam"</span>] items.push(<span class="hljs-string">"lee"</span>, <span class="hljs-string">"james"</span>); <span class="hljs-regexp">//</span> [<span class="hljs-string">"dan"</span>, <span class="hljs-string">"john"</span>, <span class="hljs-string">"liam"</span>, <span class="hljs-string">"lee"</span>, <span class="hljs-string">"james"</span>]</pre></div><h2 id="4578">How do you remove a specific item from an array?</h2><p id="2924"><code>splice</code> function uses the index to remove an item from an array.</p><p id="1a54"><code>filter</code> uses a callback function.</p><h2 id="41dd">Why is JavaScript called a loosely typed or a dynamic language?</h2><p id="cec3">JavaScript is called a loosely typed or a dynamic language because JavaScript variables are not directly associated with any value type and any variable can be assigned and re-assigned values of all types.</p><p id="5149"><i>Example:</i></p><div id="1c5c"><pre>let someLet <span class="hljs-operator">=</span> <span class="hljs-number">10</span><span class="hljs-comment">; // someLet is a number</span> <span class="hljs-attribute">someLet</span> <span class="hljs-operator">=</span> <span class="hljs-string">"Hello world"</span><span class="hljs-comment">; // someLet is now a string</span> <span class="hljs-attribute">someLet</span> <span class="hljs-operator">=</span> true<span class="hljs-comment">; // someLet is now a bool</span></pre></div><h2 id="3c25">What is “this”?</h2><p id="cdc1">The <code>this</code> keyword refers to the current object the code is being written inside.</p><h2 id="1587">How do you make an API call in JavaScript?</h2><p id="8004">Looking for one of the below:</p><ol><li>XMLHttpRequest</li><li>fetch</li><li>Axios</li><li>jQuery</li></ol><h2 id="6368">Name the API verb types which you would use in JavaScript</h2><p id="f549">Looking for the below:</p><ol><li>POST</li><li>GET</li><li>PATCH</li><li>DELETE</li><li>PUT</li></ol><h1 id="b002">Conclusion</h1><p id="8535">I’ve asked and been asked a mixture of the above questions in interviews. I think for any JavaScript interview its good to have a mixture of questions. A combination of a coding challenge(s) with some quick-fire questions is a good way to see a candidates potential.</p><p id="b135">Hope you’ve enjoyed!</p><div id="7b79" class="link-block"> <a href="https://readmedium.com/top-19-frequently-asked-typescript-interview-questions-dac4ff30c017"> <div> <div> <h2>Top 19 frequently asked TypeScript interview questions</h2> <div><h3>Common interview questions that get asked about TypeScript</h3></div> <div><p>medium.com</p></div> </div> <div> <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/0*2cPcQgQPzyBZUmhw)"></div> </div> </div> </a> </div><h2 id="2ccc">In Plain English</h2><p id="266a">Enjoyed this article? If so, get more similar content by <a href="https://www.youtube.com/channel/UCtipWUghju290NWcn8jhyAw"><b>subscribing to our YouTube channel</b></a><b>!</b></p></article></body>

24 quick-fire JavaScript interview questions

JavaScript Quickfire interview questions

Photo by Drew Hays on Unsplash

Explain the difference between “==” and “===”

“==” is used to compare two values irrespective of the datatype of variable.

“===” is used to compare two values but will be a strict check so will check the value and the datatype match.

Example(s):

"50" == 50 // true
"50" === 50 // false
50 === 50 // true

How do you check if a value is a number?

isNaN() function determines if the value is not a number.

If you useisNaN() you will have to do additional checks as you can see from the below examples.

Example(s):

isNaN(48) //false
isNaN(-1.23) //false
isNaN(5-2) //false
isNaN('123') //false
isNaN('Hello Im a real string') //true
isNaN('2005/12/12') //true
isNaN('') //false
isNaN(undefined) //true

How do you convert a string to an int?

parseInt() converts a string to a whole number

Example;

parseInt("30", 10) // 30
parseInt("55px", 10) // 50
parseInt(2.55, 10) // 2

parseFloat() converts a string to a point number (with a decimal)

Example:

parseFloat("30") // 30
parseFloat("55px") // 50
parseFloat(2.55) // 2.55

You could also accept

Number() converts a string to a number. This can be a whole number or point number. These can often be less safe than using parseInt or parseFloat

Name the different loops in JavaScript

for - loops through a block of code a number of times

for/in - loops through the properties of an object

for/of - loops through the values of an iterable object

while - loops through a block of code while a specified condition is true

do/while - also loops through a block of code while a specified condition is true

What is the difference between var , let and const?

var can be redeclared and updated.

let can be updated but not declared

const cannot be updated or redeclared.

Example:

var myNumber = 10;
var myNumber = 20;
// No error
let myNumber = 10;
let myNumber = 20;
// In the console I get an error:
Uncaught SyntaxError: Identifier 'myNumber' has already been declared

What is the difference between NULL and undefined ?

NULL is an assignment value. It can be assigned to a variable as a representation of no value.

undefined means a variable has been declared but has not yet been assigned a value

Example:

let hi; // undefined
let hi = NULL; //NULL

What is the typeof operator used for?

typeof the operator returns a string indicating the type of the unevaluated operand.

Example:

typeof(122) // "number"
typeof(122.55) // "number"
typeof("I'm a string") // "string"
typeof({ name: "James Smith"}) // "object"
typeof(false) // "boolean"

How do you check if an object is an array?

isArray() function determines whether an object is an array.

What is a callback?

A callback function, also known as a higher-order function, is a function that is passed to another function as a parameter.

Explain what default function parameters are

They allow named parameters to be initialized with default values if no value or undefined is passed.

Example:

function addTogether(x, y = 1) {
     return x + y;
}
addTogether(10, 10) // 20
addTogether(10) // 11

What are ES6 modules?

They Organise a related set of JavaScript code. A module can contain variables and functions. A module is nothing more than a chunk of JavaScript code written in a file.

Name the two different ES6 exports

Default exports are used when a module only needs to export only a single value.

Named exports are distinguished by their names. There can be serval named exports in a module.

What are Promises?

They are used to handle asynchronous operations. They can handle multiple asynchronous operations easily and provide better error handling than callbacks and events.

What are the different states in promises?

A Promise has three states:

  1. fulfilled: Action related to the promise succeeded
  2. rejected: Action related to the promise failed
  3. pending: Promise is still pending i.e not fulfilled or rejected yet

What is async/await?

async before a function means one simple thing: a function always returns a promise. Other values are wrapped in a resolved promise automatically.

await makes JavaScript wait until that promise settles and returns its result.

What is the difference between local storage & session storage?

local persists until explicitly deleted. Changes made are saved and available for all current and future visits to the site.

session changes are only available per tab. Changes made are saved and available for the current page in that tab until it is closed. Once it is closed, the stored data is deleted.

Name the different DOM selectors

  • getElementsByTagName()
  • getElementsByClassName()
  • getElementById()
  • querySelector()
  • querySelectorAll()

What is a closure?

We need closures when a variable which is defined outside the scope in reference is accessed from some inner scope.

How do you add an item(s) to an array?

You can use the push() function to append an item to an array. It can also add many items at the same time.

Example:

let items = ["dan", "john"];
items.push("liam");  // ["dan", "john", "liam"]
items.push("lee", "james"); // ["dan", "john", "liam", "lee", "james"]

How do you remove a specific item from an array?

splice function uses the index to remove an item from an array.

filter uses a callback function.

Why is JavaScript called a loosely typed or a dynamic language?

JavaScript is called a loosely typed or a dynamic language because JavaScript variables are not directly associated with any value type and any variable can be assigned and re-assigned values of all types.

Example:

let someLet = 10; // someLet is a number
someLet = "Hello world"; // someLet is now a string
someLet = true; // someLet is now a bool

What is “this”?

The this keyword refers to the current object the code is being written inside.

How do you make an API call in JavaScript?

Looking for one of the below:

  1. XMLHttpRequest
  2. fetch
  3. Axios
  4. jQuery

Name the API verb types which you would use in JavaScript

Looking for the below:

  1. POST
  2. GET
  3. PATCH
  4. DELETE
  5. PUT

Conclusion

I’ve asked and been asked a mixture of the above questions in interviews. I think for any JavaScript interview its good to have a mixture of questions. A combination of a coding challenge(s) with some quick-fire questions is a good way to see a candidates potential.

Hope you’ve enjoyed!

In Plain English

Enjoyed this article? If so, get more similar content by subscribing to our YouTube channel!

JavaScript
Programming
Software Engineering
Web Development
React
Recommended from ReadMedium