JavaScript
Some useful references that you can go through to refresh your JavaScript knowledge:
- JavaScript Notes & Reference: To find everything in one place about JavaScript.
- ES6 Tutorial: ES6 tutorials and guidelines.
- ECMAScript History: Various versions of ECMAScript.
- Clean Code concepts adapted for JavaScript: To learn and practice the clean coding concepts of JavaScript, please follow this link.
- ESNext: A comprehensive list of all additions to ECMAScript after ES6.
Try it out!
1. Fix the following code snippet that attempts to calculate the sum of an array.
/**
* Calculates the sum of all elements in an array.
*
* @param {number[]} arr - The array of numbers to sum.
* @returns {number} The sum of the elements in the array.
*/
function sumArray(arr) {
let sum = 0;
for (let i = 0; i <= arr.length; i++) {
sum += arr[i];
}
return sum;
}
console.log(sumArray([1, 2, 3, 4])); // Expected output: 10
2. What will be the output of the following, and why?
let a = 3;
let b = "3";
console.log( a+b );
console.log( b+a);
console.log( b*a );
console.log( a*b );
console.log( a/b );
console.log( b/a );
console.log( a-b );
console.log( b-a );
Ideas to Explore:
- What are closures in JavaScript?
- What is the event loop in JavaScript?
- What is the difference between null and undefined in JavaScript?
Quizzes