What Nobody Tells You About Entrepreneurship

The key truths that most people don't know about entrepreneurship and often end up finding out the hard way. We cover the good, the bad, and the ugly side of entrepreneurship that you will wish you had known before you started.

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Top 10 JavaScript Coding Interview Questions and Answers

As a web developer we must face some coding problems in interviews.

Let’s see how we handle these coding questions.

Solution:

Surprisingly, these two functions will not return the same thing. Rather:

{bar: “hello”}

undefined

Not only is this surprising, but what makes this particularly gnarly is that func2() returns undefined without any error being thrown.

The reason for this has to do with the fact that semicolons are technically optional in JavaScript (although omitting them is generally really bad form). As a result, when the line containing the ‘return’ statement (with nothing else on the line) is encountered in func2(), a semicolon is automatically inserted immediately after the return statement.

No error is thrown since the remainder of the code is perfectly valid, even though it doesn’t ever get invoked or do anything (it is simply an unused code block that defines a property bar which is equal to the string ‘hello’).

This behavior also argues for following the convention of placing an opening curly brace at the end of a line in JavaScript, rather than on the beginning of a new line. As shown here, this becomes more than just a stylistic preference in JavaScript.

solution:

solution:

An educated answer to this question would simply be: “You can’t be sure. it might print out 0.3 and true, or it might not. Numbers in JavaScript are all treated with floating point precision, and as such, may not always yield the expected results.”

The example provided above is classic case that demonstrates this issue. Surprisingly, it will print out:

0.30000000000000004

false

A typical solution is to compare the absolute difference between two numbers with the special constant Number.EPSILON:

solution:

solution:

solution:

solution:

solution:

The output would be 5. When we use the ‘delete’ operator to delete an array element, the array length is not affected from this. This holds even if you deleted all elements of an array using the ‘delete’ operator.

solution:

The code will output 1, ''truexyz’' ,2,1. Here's a general guideline for addition operators:

solution:

The output would be 1. The ‘delete’ operator is used to delete the property of an object. Here x is not an object, but rather it's the global variable of type ‘number’.

Wish me luck !

Add a comment

Related posts:

Designing a trading algorithm

It is assumed that trading in markets like Nifty, Sensex, etc, is carried out by individuals(human beings) with knowledge and required qualification. But with the advent of computers things have…

Machines of Creativity

Artificial intelligence will displace 40% of jobs worldwide in the next 15 years. Creative jobs, however, require unorthodox thinking and imagination, concepts that are not fully understood by…

Afterglow

the sun casting a melon glow the day slipping to evening a chill slides in tempering the steam of the afternoon cooling the damp on my skin your whiskers rough on the nape of my neck nuzzling deeper…