Skip to content

Instantly share code, notes, and snippets.

@dhruv-m-patel
Last active March 17, 2021 03:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dhruv-m-patel/e1990738f81d2ece3d9f06b06d6f45b4 to your computer and use it in GitHub Desktop.
Save dhruv-m-patel/e1990738f81d2ece3d9f06b06d6f45b4 to your computer and use it in GitHub Desktop.
JS Code Samples
// What would be the outcome of this statement?
const [a, b] = [10, 20];
// What is the "..." in following statement? What does it do?
const [a, b, ...rest] = [10, 20, 30, 40, 50];
// What is this statement doing?
const { a, b } = response;
// What would be the result of the following statements?
const response = {
a: null,
b: {
x: "foo"
}
};
const {
a = 10,
b: output
} = response;
// What is the "?." called in here? What does it do?
if (a.b?.c?.d) {
..........
}
// What is the "??" operator called? What does it do?
const a = b ?? c;
// What would be the end result of the following?
const a = 10;
const b = 5;
const c = 20;
const d = (x) => x * 10;
const result = [a, b, c].map(d);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment