Skip to content

Instantly share code, notes, and snippets.

@aleksamarkoni
Created March 5, 2018 21:56
Show Gist options
  • Save aleksamarkoni/76225333e9971c9774c63b9c53189ad2 to your computer and use it in GitHub Desktop.
Save aleksamarkoni/76225333e9971c9774c63b9c53189ad2 to your computer and use it in GitHub Desktop.
JavaScript Question
1) Find suboptimal code in the following snippet:
for (var i = 0; i < 100; i++) {
$("#list").append(i + ", ");
};
------------------------------------------
2) What is the result of the following code snippet:
var a=1;
function inc(x) {
x++;
x-=2;
}
console.log(inc(a))
-----------------------------------------------
3) What is the result of the following code snippet:
var a={x:1};
function incX(a) {
a.x++;
a.x-=2;
}
incX(a)
console.log(a.x)
-------------------------------------------
4) What is the result of the following code snippet:
var a=1;
function inc(a) {
a++;
a-=2;
}
inc(a)
console.log(a)
-----------------------------------------------------
5) What is the result of the following code snippet:
var a = 10;
function incA() {
a++;
}
incA();
console.log(a);
-----------------------------------------------------
6) For given part of HTML:
<div id="test" class="red">TEST</div>
and CSS:
#test{
color:blue;
}
.red {
color: red;
}
what will be the final color of TEST text?
---------------------------------------------------
7) What is the result of the following code snippet if code is run in any browser:
function logThis() {
console.log(this)
}
logThis();
---------------------------------------------------
8) What is the result of the following code snippet if the code is executed in any browser:
function logThis() {
console.log(this)
}
var a = {logThis:logThis}
a.logThis();
---------------------------------------------------
9) What has to be the value of a so that the value of b is false?
var b = a===a;
----------------------------------------------
10) What is the result of the following code snippet:
var a = 1;
var b = true || a++;
console.log(a);
-----------------------------------------------
11) What is the result of the following code snippet:
var a = 1;
var b = true && a++;
console.log(a);
------------------------------------------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment