Welcome to the world of job-hunting as a newly graduated fullstack developer! The competition is fierce, and landing your dream job requires a combination of technical skills, strong portfolio, and a confident interview presence. In this blog, we'll focus on the latter by preparing for a technical coding interview overnight using JavaScript.
JavaScript is a widely used programming language in web development, making it an essential skill for fullstack developers. The purpose of this blog is to help you brush up on your JavaScript skills in a short amount of time, with the aim of passing your technical coding interview with flying colors. We'll be covering key concepts, common interview questions, and tips for success. By the end of this guide, you'll be equipped with the knowledge and confidence to tackle any technical coding interview that comes your way!
Arrays
Arrays are one of the most fundamental data structures in JavaScript, and their methods are an important aspect of any technical coding interview. In this section, we'll go over three of the most commonly used array methods: map, filter, and forEach.
**Map **is used to transform each element in an array and return a new array with the same number of elements. For example, if you have an array of numbers and you want to square each element, you can use the map method to achieve this.
let numbers = [1, 2, 3, 4, 5];
let squares = numbers.map(function(num) {
return num * num;
});
console.log(squares); // [1, 4, 9, 16, 25]
The Map method in JavaScript is a powerful tool that allows us to transform elements in an array into a new array. It is a widely used method in software development and is often a topic of discussion in technical coding interviews. Let's dive deeper into the Map method and see how we can use it in real-life examples.
One of the simplest examples of using the Map method is to square each element in an array of numbers. By passing a callback function to the Map method, we can perform the desired operation on each element in the array and return a new array with the results.
let words = ['hello', 'world'];
let uppercaseWords = words.map(function(word) {
return word.toUpperCase();
});
console.log(uppercaseWords); // ['HELLO', 'WORLD']
The Map method can also be used to extract properties from an array of objects. In this example, we extract the name property from each object in the array and return a new array with the names.
let numbers = [1, 2, 3, 4, 5];
let strings = numbers.map(function(num) {
return num.toString();
});
console.log(strings); // ['1', '2', '3', '4', '5']
Finally, the Map method can also be used to convert an array of numbers to an array of strings. In this example, we use the toString method on each element in the array to get the desired result.
These are just a few examples of how the Map method can be used to transform elements in an array. The versatility of this method makes it a critical tool in the arsenal of any software developer. Whether you're preparing for a technical coding interview or working on a real-life project, understanding the Map method is a must.
**Filter **is used to select certain elements from an array based on a certain condition. For example, if you have an array of numbers and you want to select all even numbers, you can use the filter method to achieve this.
let numbers = [1, 2, 3, 4, 5];
let evens = numbers.filter(function(num) {
return num % 2 === 0;
});
console.log(evens); // [2, 4]
The Filter method in JavaScript is another useful tool that allows us to filter elements in an array based on certain conditions. It is a commonly used method in software development and is often a topic of discussion in technical coding interviews. Let's take a closer look at the Filter method and see how it can be used in real-life examples.
Example 1: Filter even numbers from an array
let numbers = [1, 2, 3, 4, 5];
let evenNumbers = numbers.filter(function(num) {
return num % 2 === 0;
});
console.log(evenNumbers); // [2, 4]
One of the simplest examples of using the Filter method is to filter even numbers from an array. By passing a callback function to the Filter method, we can evaluate each element in the array and return a new array with the elements that meet the specified condition. In this case, we are checking if the number is even using the modulus operator % 2.
Example 2: Filter words with more than 3 letters from an array
let words = ['hello', 'world', 'hi'];
let longWords = words.filter(function(word) {
return word.length > 3;
});
console.log(longWords); // ['hello', 'world']
Another common use case for the Filter method is to filter words with more than 3 letters from an array. In this example, we evaluate each word in the array and return a new array with the words that have a length greater than 3.
My personal favourite
Example 3: Filter objects based on a property value
let objects = [
{name: 'John', age: 28},
{name: 'Jane', age: 32},
{name: 'Jim', age: 25}
];
let adults = objects.filter(function(obj) {
return obj.age >= 18;
});
console.log(adults);
/*
[
{name: 'John', age: 28},
{name: 'Jane', age: 32}
]
*/
These are just a few examples of how the Filter method can be used to filter elements in an array. The Filter method is a great tool for cleaning up arrays and making data more manageable. Whether you're preparing for a technical coding interview or working on a real-life project, understanding the Filter method is a must.
ForEach is a method used to execute a function on each element in an array. It's a great tool for iterating over arrays when you need to perform operations that don't necessarily return a new array. For example, if you want to log each element of an array, you can use the forEach method.
let numbers = [1, 2, 3, 4, 5];
numbers.forEach(function(num) {
console.log(num);
});
// This will log: 1, 2, 3, 4, 5
The forEach method is versatile and essential for many JavaScript operations. Unlike map and filter, forEach doesn't return a new array; it's used for executing side effects like logging data, updating an external variable, or modifying the array elements themselves.
Practice Makes Perfect
To prepare for your interview, practice writing and understanding these methods in various scenarios. Here are a few exercises:
Use the map method to convert temperatures from Celsius to Fahrenheit.
Filter out all odd numbers from an array using the filter method.
Use forEach to calculate the sum of all elements in an array.
Remember, technical interviews are as much about your problem-solving process as they are about getting the correct answer. Practice these JavaScript concepts, participate in mock interviews, and keep a positive attitude. With these strategies, you'll be well-prepared to ace your technical coding interview.
Keep an eye out for more insightful parts in this series, where we'll continue to delve into the world of JavaScript and technical interviews. Your journey to becoming a skilled full-stack developer is just beginning!
About the Author:
Hello! I'm Sidharth Nayyar, a Full Stack Developer with a love for all things JavaScript, React.js, and Node.js. My journey through the world of computer science has been filled with exciting challenges and learning experiences. When I'm not deep in code, you can find me exploring the vibrant city of Vancouver, sharing tech tips, and connecting with fellow developers. My passion is making tech accessible and fun, and I'm here to share that adventure with you. Let's dive into the world of web development together!
You can check out my project on my portfolio
Top comments (1)
Hey! To apply for IT/Tech positions, I leave you the referral link to Outdefine, our job board with several remote job searches open for IT or Tech profiles with different levels of seniority in different areas (marketing/software/development, UX and +), in case anyone is interested or knows someone with a tech profile who needs a job: outdefine.com/r/JulietaCura-4363
You can find many jobs for technical and not so technical, but digital profiles too. And you can also get rewards in tokens on the platform, connect with our community of professionals and companies in the Community section, and it's free to use, of course!