Common Mistakes In Java Script Function And Coding Tests And How To Avoid Them?


JavaScript function

What is the best way to select the best people for your team? If you’re like thousands of other managers, you don’t think it’s enough to just review your resume. Some companies require coding tests, and some offer assignment projects. Some require both.

Still, there are many good sites these days to practice or take algorithm coding tests. Codility, HackerRank, TopCoder were the top applications.

Whenever we have the opportunity to review resumes and coding test results at the team level, we can learn by yourself by looking at the coding styles and techniques of other applicants. Nevertheless, it is a pity that many applicants make a common mistake each time, and we leave a record to reflect on. So, we will tell you the javascript function and different solutions for a javascript object.

Before reading

The most important thing in the coding test for employment/retirement purposes is the score. The most important thing is whether you exceed the standard score or not. It is next to infer and analyze this person’s meticulousness, delicacy, inclination, and stubbornness. So, what I’m going to introduce now may be minor, not major. Also, we hope that even if you are reading this article now, you will never be a developer without skills. Also, since this article is a powerful subject, it can be very different from your experience. You can also use the javascript online editor.

This article is not intended for any particular person.

What are JavaScript errors?

How do I fix JavaScript errors?

What are the types of functions in JavaScript?

What are the important topics in JavaScript?

Var, let and constants

In terms, believe it or not, but in my experience, by far, is about 40-50% of the applicant var and let or var and const wrote mix. Of course, that doesn’t mean you should always var or const.

What we see in the code is that: First, variables are declared with var and let. let Is a reserved word available since ECMAScript 2015 (commonly called ES6), while var has existed since the first version of JavaScript, and another var that can be seen also contained in the statements.

var minCount -> let minCount
var maxCount -> let maxCountfor (var we= 1; ...) -> for (let we=1; ...)

If this var is used in combination with other variable reserved words, the code reviewers will inevitably write the score. In particular, if your score is draped across the cut line, you can’t take a look at how to make this mistake. Also, some resumes may say that you are good at React or other modern JavaScript libraries, but you have to understand the differences between JavaScript versions. (Because honestly, incorporating coding tests, there is a problem to solve while using the difference between block scope and function scope.)

Of course, the best as of now is var to code only with let and without using const. let. There aren’t even a few people who are currently rejecting const this, so it’s great to do so if you can code it using only. Instead, if you are confused, it var maybe your strategy to use it rather. team up with a person who has been working with ES5, so you can go any way.

JavaScript Tutorial – An Ultimate Guide for Beginners

What you should do?

var, Either use let and const use only (recommended)

What you shouldn’t do?

var And let, const let’s not mix everything

semicolon(;)

Many programming languages ​​adopt a semicolon at the end of a sentence. Typically, Java will fail if you don’t add a semicolon. (But not) JavaScript, however, is relatively free of semicolons. A semicolon may or may not be added. When you do so, the responsibility for what happens afterwards is left entirely to the developer. Attaching a semicolon at the end is almost a rule, but some libraries still have conventions that don’t add a semicolon.

Not using semicolons is just plain and simply, wrong. The language itself does not spit out errors, but where is it wrong? It’s better if you just code carefully. Still, there are reasons for the rules that many people follow. If you take this link, you can see a well-arranged post on why you should use semicolons.

What we want to say here is not the pros and cons of using semicolons. We are talking about coding tests. You may or may not use semicolons, but why on earth do you mix the two rules?

Fortunately these days, linter automatically appends a semicolon to the back, so this can be fine in actual coding. As an example, we also omit semicolons quite often. And when we saw a semicolon at a time when we saved it.

But be careful with coding tests. The coding test is primarily aimed at looking at your basic algorithm literacy and problem-solving skills, but it is also a coding test that gives you justification for tackling as many times as you like in the interview.

“Why did you write a semi-colon and not use it? Why?”

“Oh, it’s a habit that we don’t care about auto-completion when wecode. ”

“… Oh, yes it is. ”

What you should do?

Always use semicolons. If you feel like it is not my style, we recommend not using any.

What you shouldn’t do?

Prohibition

Match operator

This may be related to the second item. There are various ways in JavaScript to compare values. Among them, ===and ==is an operator that compares equality between two values. As a side note, everyone wonders how to call that operator. we call it 는는는mockup 는는.

It is currently the national rule as of 2019 that this section is always used. The reason is that if you use a case unexpected in true, false because it can be returned in the results. Therefore, it is preferable to use ==, unless it is necessary to use ===.

But some libraries null and undefined should also be widely used in the following way whether it’s ok for the comparison of the two times.

The code for the example can be a bit confusing. Let’s assume that the above function is called as follows:

The results we wanted to be were true (1, 2, ‘0’, ‘1’, ‘2’). we wanted to remove only the number 0, but it was filtered out to the string 0. Why does that happen? This ==is because the silver character ‘0’is also false. On the other hand, ===is’ 0 ‘0’not false considered because it is not an empty string.

What you should do?

Always use ===

What you shouldn’t do?

Don’t use == unless it is absolutely necessary for the context

Immutability

The concept of immutability has become more researched and considered more important, especially since the advent of React, View, and Angular. Many developers have pondered how to get a better, more stable state value every time JavaScript history is rewritten from jQuery to the review-en era. There is a concept that naturally emerged from such concerns. It is the object’s original preservation, i.e. immutability, which prevents side effects by reducing its influence on the external scope and preserves the state of the original object completely.

The first thing a developer should follow in a function is not to modify the value entered as an argument. At the moment of modification, the function can never be a pure function until the end of the function. This is another deep story, so let’s go on to this, and there are places where the rules just mentioned in the actual code must be followed, but there are places where they are not followed.

Perhaps this is not very meaningful for solving problems in coding tests. However, you may be asked the following questions at the interview.

“If this function receives actual data, will the original of this object change?”

So what should you do? We slice and copy an array from inside a function and use it, and when we need to pass an object, we pass only the necessary properties in the object. If the whole object is needed, try to code it in the direction that does not damage the original object as much as possible.

We think this fourth item is much more important than the other three. Coding testing, as we said before, is primarily a system to make sure you have the least amount of problem-solving. Nevertheless, it is forbidden to think that a coding test will end simply by passing a score. Although it is up to the interviewer to decide whether or not to use the result of the coding test in the interview, it is good not to think that you will not have done a primary analysis of you just because you did not ask about the coding test in the interview.

First of all, we think, we can finish this chapter and write the story we wanted to tell in the summary column.

What you should do

Let’s copy and use the value by deep copying to a new object

What you shouldn’t do

Let’s not change the argument, no matter what. It is likely to cause side effects.

Ternary operator

This part was not in the original plan, but when we wrote it, we thought about it at the end, so we will summarize it.

Although many have reviewed as a coding test the sound we had heard a lot from the side than we thought “This is why this code is not complicated,” it was. I’m not a genius, and there are a few code styles that we can’t help but frown, no matter how high in my career and how good we are. One of the most representative styles is one that tries to finish in one line anyway. One of these sources is the ternary operator.

Ternary operator? Isn’t that simple and good to use? Of course, it is. The ternary operator doesn’t know who developed it, but it should be praised. You have to do it twice. But, what if we coded like this?

To be honest with that example, we also missed where the connection was. This example is too extreme, but simply.

Why not rethink the use of the ternary operator if it’s not a form?

Ah, we saw a couple of years ago when we coded so many ternary operators into one line. we were very startled.

What you should do

Use the ternary operator when you can handle it neatly.

What you shouldn’t do

If you simply want to use the ternary operator because you don’t want to use it, consider whether you use it when you need it.

Theorem

The coding test is the first gateway to passing the paper review. Passing the exam with a high score should be the top priority.

However, we want to reconsider that coding testing is not everything. Reviewers take your coding tests more time than you think and get more information than you think. The coding style is natural, how meticulous, how stubborn, believe it or not, but even a very experienced person has reports of coding tests and some people who have a sense of what kind of person he has worked for.

Wrapping Up!

Thanks for reading this article. We hope you have found value in what we have written. If you do have any more concerns regarding the article, please feel free to address them in the comments section below. We will be happy to resolve them for you. We hope now you know the javascript function, javascript online editor, and javascript compiler online.