Really cool & mind blowing freaking javascript advanced indepth concept questions

Really cool & mind blowing freaking javascript advanced indepth concept questions

i dont think so , writing content for an hour , sharing some experience which i did encountered earlier, that's seems always pretty cool , i did love to share via article

its not gonna leads to earn money , the think is out action always intended to be earn money

You are the source to be happy someone life , money will find your way to reach you

just skip out of philosophy

i have to tell before i am gonna start , execuse for my bad english grammer !

such a wonderful experience with javascript assessment , this result indulge me to learn indepth javascript concept

In this article, you will denatively grasp some core idea about js and how js was becaved in many situations ,

looking answer always blaming me

however interview questions would be inside of js , i hope , we can answer all of the questions easily as per my knowledge but my final fate i got bullet shot on my head, like js saying like

u didn't realise my original power

Understanding Javascript looks like easy , finding answer for all kind of trick question you may failed sometimes, Javascript is super cool when having hands on real time programming ,if it would be on assessment ,things got changed , not easy we think about it

I would like to share all of the questions here, so every beginner and experience developer just read this articiisafterwards jump into interview, this post should helpfultional companies willing join international companies

let's dive into questions which i am faced

Javascript Mind Freaking Question I had ever seen

1 . How would you randomly pick an element from an array named "myNumbers"?

a. myRandomElement = myNumbers[Math.floor(Math.random() * myNumbers.length)]

b. myRandomElement = myNumbers[Math.ceil(Math.random() * myNumbers.length)];

c. myRandomElement = myNumbers[Math.random(myNumbers.length)];

d. myRandomElement = Math.random(myNumbers.length);;

2. Which of the following would not result in an error?

a. var ob = {}; ob.anUndefinedVariable = anUndefinedVariable

b. var aDefinedVariable = null;

 var str = 'text'; 

str += aDefinedVariable.toString();

c.console.error(typeof anUndefinedVariable);

d. var myFn = function () { myFn(); }; myFn();;


3.A cookie is set using the below Javascript statement. When will it expire? document.cookie = "foo=bar;secure";

a. When the browser is closed

b. When the user navigates away from the page that set the cookie

c. Never

4. Which of the following cannot be modified/controlled by a browser extension directly?

Select one:

a. DOM contents (HTML) on a pag

b. Applied styles (CSS) on a page

c. Value of a JavaScript variable on a page

d. Network requests for a pagee

5. Which of the following is not supported by native JS implementation in popular browsers and Node.js environment?

Select one:

a. Parallel processin

b. File read

c. Static typing

d. Scheduling tasksg

6. How do you write a self executing function ?

a. function x() { /* Code */ }; x()

b. (function x() { /* Code */ }) x();

c. function x() { /* Code */ } (x();)

d. (function () { /* Code */ })();;

7. What's computed by this code?

(function(n){return (n && n*arguments.callee(n-1)) || 1;})(10);

a. 10

b. Nothing, it's an infinite loop

c. 10 to the power of 10

d. 10!/10

e. The 10th Fibonacci number!

8. How do you remove a property "prop" from an object "obj"?

a. obj['prop'] = null

b. obj.prop = undefined;

c. delete obj.prop;

d. remove(obj['prop']);;

9. Assuming "a" refers to a function, how would you execute "a" after a delay of one second?

a. setInterval("a()", 1000000)

b. setTimeout(a, 1000);

c. window.sleep(1);a();

d. a.defer(100);

e. eval("a()", 10000);

f. delay({callback: a, milliseconds: 1000});

g. You cannot do that in Javascript;

10. If the `async` attribute is added to <script> tag, what will it do ?

Select one:

a. Browser will load the script in parallel and exeute it as soon as it is loade

b. Browser will load the script in sequence and execute it as soon as DOM is ready

c. Browser will load the script in parallel and make the code in the file asynchronous

d. Browser will load the script in sequence and make the code in the file asynchronousd

11 . Which of the following is a type of attack on web application?

a. CSR

b. XSS

c. Clickjacking

d. All of the aboveF

12.Why doesn't the following regular expression work?

function hasANumber(value) 

 

                return /^.*[0-9]*.*$/.test(value);

 

}{

Select one

a. It will not match strings that contain a decimal like 'abc 12.34'

b. The * modifier after [0-9] means it will match for strings with no numbers

c. \d should be used instead of [0-9].

d. The g flag is not set so it will not return true if there are multiple numbers.

e. It will not match strings with numbers at the beginning or end like '123'..

13.What does it mean when a function or feature is referred to as "asynchronous"?

a. It is highly efficient and very fast

b. It is difficult to use.

c. It will not work on older browsers.

d. It requires multiprocessor support.

e. It will not block the current execution..

14.. How can one ensure that a series of asynchronous calls are invoked in the correct order?

Select one:

a. Use `setInterval()` and invoke each call after a sufficient delay

b. Set each function as an element in an array and iterate over this array.

c. Each asynchronous call should accept a callback to execute the next call in the series when it completes.

d. Use `Math.random()` and hope for the best.

e. It is not possible..

15.Below is a function for executing asynchronous tasks in parallel. Why doesn't it work as expected?

 

function doInParallel(tasks, cb) {

               var numTasks = tasks.length;

tasks.forEach(function (task) {

 task();

 numTasks -= 1;

   if (numTasks === 0) {

 

    cb();

  }

    });}

doInParallel([...], function () {

               // Excute only when tasks are complete

})

a. The callback function will be executed as soon as the last task is invoked but before any of the tasks complete

b. The doInParallel function should return `this`

c. `cb()` should be called after the `forEach`; there is no reason to track the number of tasks.

d. All of the above..

16.. What does the `new` operator do when used in conjunction with a function call?

a. Uses classical inheritance to instantiate an object of that class

b. Creates a new Object instance assigned to `this` that will be the return value by default.

c. Performs garbage collection on unused variables in the current scope and runs the function.

d. Ensures that the return object's prototype contains the correct properties.

e. Instantiate an object which can be extended with additional methods.

17.Given the below piece of code, what should `obj.value` be set to in order for the if-condition to be true?

var obj = {};

obj.value = ???;

if (obj.value === obj.value.value.value) {

}

a. thi

b. obj.value

c. function () {return true;}

d. obj

e. windows

18.Given the below code, which of the following is true:

var a = '',

               b = '',

               c = {value1: a, value2: b},

               d = {value2: b, value1: a};

a. a === b && c === 

b. a === b && JSON.stringify(c) === JSON.stringify(d)

c. c === c.value1 && d === d.value2

d. c.value1 === d.value2 && c.value2 === d.value1

e. a === c === d === bd

19. Which of the following can set the background color of a DOM element to red?

var element = document.getElementById('my-element');

a. element.style.backgroundColor = '#f00'

b. element.bg.color.red = true;

c. element.setBackgroundColor('#ff0000');

d. element.style({"background-color: red;"})

e. element.style.background-color = red;;

20.Which of the following is an acceptable way to add a click event handler to a DOM element?

var element = document.getElementById('my-element');

Select one:

a. element.click = function () {};

b. element.on('click', function () {});

c. element.addEventListener('click', function () {});

d. element.onclick(function () {});

e. (function onElementClick() {}(element));


I knew , you entirely tired to get results

No alt text provided for this image



21. The below code doesn't work as expected. What could be wrong?

(Assuming that elements with a class of 'button' receive a suitable styling)

for (var i=0 ; i<10 ; i++) {

document.body.innerHTML += "<div class='button' id='button"+i+"'></div>";

document.getElementById("button"+i).onclick = function() {

                               alert("You clicked button number "+this.id.replace(/^button/, ""));

               }

}

a. Existing event handlers below "document.body" are lost when "innerHTML" is overwritten

b. "document.getElementById" cannot be used immediately after "innerHTML" has been altered, "setTimeout" must be used.

c. "this.id" cannot be used from within the event handler, causing a runtime error when the click event is handled.

d. "document.getElementById" only works in Internet Explorer, the "document.all" collection must be used..

22 . How can this function be improved?

function removeLeadingAndTrailingWhitespaceFromString(str) {

return str.replace(/(^\s+)|(\s+$)/ig, "");

}

a. The "g" flag can be omitted from the regular expression

b. The "*" quantifier should be used instead of "+" to avoid unnecessary replacements.

c. There's no need to use capturing parentheses in the regular expression because the values aren't used.

d. All of the above..

23. A DOM element in the page is not visible, but is taking up the space on the page. What CSS / style has been set?

Select one:

a. display: visible;

b. display: none;

c. visibility: hidden;24.

d. visibility: collapse;

24. Why doesn't the below code work as expected?

 var isOdd = function(n) {return n&1;},

 isDivisibleByThree = function(n) {return !(n%3);},

   addOne = function(n) {return n+1;};

 alert([1,2,3,4,5,6,7].map(addOne).filter(isOdd && isDivisibleByThree).length);

Select one:

a. The "isOdd" test never gets called

b. The "isOdd" test is wrong.

c. The "isDivisibleByThree" test never gets called.

d. The "isDivisibleByThree" test is wrong.


25.Why doesn't the below code alert "foobar" as expected?

 function StringBuffer(initialStr) {

               this.append(initialStr);

}

 

StringBuffer.prototype = {

               items: [],

               append: function(str) {

                               this.items[this.items.length] = str instanceof StringBuffer ? str.toString() : str;

                               return this;

               },

               toString: function() {

return this.items.join("");

               }

};

 alert(new StringBuffer("foo").append(new StringBuffer("bar")).toString());

a. The "items" array is shared among all instances of "StringBuffer"

b. "initialStr" is appended to all instances of "StringBuffer" whenever the "toString" method is called.

c. The "append" method returns the wrong object.

d. "toString" doesn't call the "toString" method on each object in "items"..

26. Rename "f", "a", and "b" to something more suitable:

function f(a, b) {

               return function() {

                               return a.apply(b, arguments);

               };

}

a. f:bindFunctionToScope, a:fn, b:scop

b. f:delayExecution, a:fn, b:milliseconds

c. f:applyFunctionToArray, a:array, b:fn

d. f:map, a:array, b:fne

27. Why doesn't the below function work as expected?

var isUndefinedOrNull = function(obj) {

               return /^(?:undefined|null)$/.test(typeof obj);

};

Select one:

  • a. "undefined" is a reserved word, not a type.
  • b. Regular expressions work on strings, not types.
  • c. It will return true for the empty string.
  • d. All of the above.

e. None of the above. Something else is wrong.

28 . Why doesn't the following function work?

function printZeroToNinetyNine() {

for (var i = 0; i < 100; i += 1) {

                               setTimeout(function () {

                                               console.log(i);

                               }, 0);

               }

 

}

Select one:

  • a. There is an off-by-one error.
  • b. The delay of zero in setTimeout means the inner function is never called.
  • c. The variable `i` is not scoped to the inner function.
  • d. The function name is too long.

e. It is not possible to write a function in a for-loop

29. What is the output of the following function?

 function delayedPrint() {

               for (var i = 0; i < 100; i += 1) {

                               (function (value) {

                                               setTimeout(function () {

                                                               console.log(i);

                                               }, 1000 * value);

                               }(i));

               }

}

Select one:

  • a. The numbers 0 to 99 with a delay of 1000ms between each line.
  • b. The numbers 0 to 99 with a 1000ms delay before the first one but no delay between numbers
  • c. The number 100 printed 100 times with a 1000ms delay before the first one but no delay between numbers.
  • d. The number 100 printed 100 times with a delay of 1000ms between each line.
  • e. The numbers 0 to 99 with an increasing delay between each line, starting from 0ms and ending with 1000ms.

30.What is the output of the following piece of code?

function createObject(name, value) {

               var returnObject = {};

               returnObject[name] = value;

               returnObject['addTo' + name] = function () {

                               return value += 1;

               };

               return returnObject

}

31. Which of the following statement is generally true ?

Select one:

  • a. `async` can only be used in function if the function is declared with `await`
  • b. `await` can only be used in function if the function is declared with `async`
  • c. `async` and `await` keywords can be used independently          


32. What is the return value of "setInterval"?

Select one:

  • a. An object that make is possible to queue up messages/objects for the next invocation of the function passed to "setInterval".
  • b. An ID that can be used with "clearInterval" to stop the interval.
  • c. An opaque object that can be used with "clearTimeout" to stop the interval.
  • d. Whatever is returned from the first invocation of the function passed to "setInterval"

33.Why doesn't the below code open an alert box with the text "foo"?

 

function wrapInObject(value) {

               return

               {

                               value: value

               }

}

alert(wrapInObject("foo").value);

Select one:

  • a. Javascript's automatic semicolon insertion causes an undefined value to be returned from "wrapInObject"
  • b. A variable cannot be used as a key in an object.
  • c. "wrapInObject" returns an object literal with a single "foo" key, not "value".
  • d. A function is only allowed to return a primitive value.


34.When making Ajax request from a browser, the same origin policy will allow communication between the following ?

Select one:

  • a. https://one.example.com/api1 and https://one.example.com/api2
  • b. https://one.example.com/api1 and https://one.example.com/api2
  • c. https://one.example.com/api1 and https://two.example.com/api2
  • d. https://one.example.com/api1 and https://one.example.com:81/api2

35.What does the function "f" do?

function f(a) {

               return function(b) {

                               return a + b;

               };

}

Select one:

  • a. Given an integer "a" it returns an anonymous function that returns the sum of "a" and the supplied argument "b".
  • b. Given a string "a" it returns an anonymous function that returns the concatenation of "a" and the supplied argument "b".
  • c. All of the above.
  • d. None of the above


35. Why doesn't this work as intended?

function makeNumberSequenceGenerator(nextValue) {

               return function() {

                               return nextValue++;

               };

}

alert(makeNumberSequenceGenerator(10).nextValue().nextValue());

Select one:

  • a. "nextValue" cannot be referenced from the inner function.
  • b. "nextValue" cannot be incremented from the inner function, it is read-only.
  • c. "nextValue" is a property on the returned object, not a method.
  • d. The return value of the "makeNumberSequenceGenerator" function doesn't have a "nextValue" property/method.

36.Complete the return statement in the function below:

 

function isFalseBooleanValue(bool) {

               // return...

}

Select one:

  • a. return bool = false;
  • b. return bool == false;
  • c. return bool === false;
  • d. return bool ==== false;

37.What's accomplished by using this construct:

(function() {

               for (var i=0 ; i<10 ; i++) {

                               alert(i);

               }

})();

instead of just:

for (var i=0 ; i<10 ; i++) {

               alert(i);

}

Select one:

  • a. The global object isn't polluted by the variable "i".
  • b. The execution of the for loop will be delayed until the entire script has run.
  • c. The loop will run in a security sandbox that cannot access the DOM.
  • d. Nothing, the two pieces of code are equivalent.


38.When making multiple HTTP requests, where each request is independent and is expected to complete, but may or may not complete, what is the best suited handling method ?

Select one:

a. `new Promise`
b. `Promise.all()`
c. `Promis.allSettled()`
d. `Promise.race()`

39 .The below code doesn't work as expected. What could be wrong?

however interview questions would be inside of js , i hope , we can answer all of the questions easily as per my knowledge but my final fate i got bullet shot on my head, like js saying like you didn't realise my original power

for (var i=0 ; i<10 ; i++) {

               var button = document.createElement("button");

               button.onclick = function() {

                               alert("You clicked button number "+i);

               };

document.body.appendChild(button).appendChild(document.createTextNode("Button "+i))}

Select one:

  • a. The variable "i" cannot be used in the onclick handler because it's defined in an outer scope.
  • b. The variable "i" will be shared among the event handlers because Javascript doesn't have block scope.
  • c. Button tags are only allowed within a "<form>".
  • d. Chaining "appendChild" calls is only supported in Internet Explorer


40. what will you get finally ?

var obj = createObject('Property', 100);

console.log(obj.Property);

console.log(obj.addToProperty());

console.log(obj.Property);

Select one:

  • a. 100, 101, 100
  • b. 100, 100, 100
  • c. undefined, undefined, undefined
  • d. 100, 101, 101
  • e. 100, 101, 102


Hooray ! finally i am copied down all questions which is really usefull. dont forgot to find the answer to this questions which will entirely change your Javascript attitude , just kick start the pro rocket engine , happy programming forever!

要查看或添加评论,请登录

社区洞察

其他会员也浏览了