Home >> Interviews Q & A >> JavaScript Coding Questions and Answers

JavaScript Coding Questions and Answers

JavaScript Coding Questions and Answers | Learn JavaScript Coding Interview Questions Answers to become Full Stack JavaScript Developer | Front-end Developer
JavaScript Coding Questions and Answers

JavaScript Coding Questions and Answers

Q:- What is JavaScript?

JavaScript(JS) is an object-based, lightweight and cross-platform, high-level, interpreted case-sensitive scripting language.

Q:- Method Overloading and Overriding in JavaScript?
  1. Method Overloading - JavaScript does not support Overloading.
  2. Method Overriding - JavaScript supports Overloading.
  3. Suppose, you have defined two or more functions with same function name, then last function will override the previously defined functions.

2.1 Overriding Custom JavaScript Function:
function sum(a, b, c) {
  return a + b + c;
}

function sum(a, b) {
  return a + b;
}

var result = sum(5, 10, 10);
console.log(result);
Output:

15

2.2 Overriding Built-in JavaScript Function:
let alert = msg => {
  console.log(msg);
};
alert("JavaScript - Overriding Built-in JavaScript Function!");
Output:

JavaScript - Overriding Built-in JavaScript Function!

Note: As we all know that by default, alert() function displays the message in the alert box. In the above example we have overriden it.

Q:- What will be the output of following js code snippet?
const number = undefined + 11;
if (number === NaN) {
  document.write("NaN");
} else if (number === 11) {
  document.write("11");
} else {
  document.write("other");
}
Output:

other

You may also like - JavaScript Interview Questions
Q:- Reverse a given string using JavaScript?
var str = "Full Stack Tutorials";
var output = str
  .split("")
  .reverse()
  .join("");
document.write(output);
Output:

slairotuT kcatS lluF

Q:- Find the sum of all elements of a given array?
var arr = [1, 2, 5, 10, 20];

//Solution - 1
var sum = 0;
for (let i in arr) {
  sum += arr[i];
}
document.write(sum);

//Solution - 2
var sum = arr.reduce((a, i) => {
  return a + i;
});
document.write(sum);
Output:

38

Q:- JavaScript startsWith and endsWith?
let name = 'Full Stack Tutorials, Latest Interview Questions and Answers!';

//startsWith
console.log(name.startsWith('Full'));         // true
console.log(name.startsWith('Tutorials'));    // false
console.log(name.startsWith('Tutorials', 11)); // true

//endsWith
console.log(name.endsWith('Answers!')); // true
Q:- Find the output?
var a=3;
var b=a++;
var c=++a;
console.log(a,b,c)
Output:

5 3 5

You may also like - React.js Interview Questions
Full Stack Tutorials

Author @FullStackTutorials | View all Articles