Linked Questions

1811 votes
36 answers
589k views

The primitive types (number, string, etc.) are passed by value. Still, objects are unknown because they can be both passed by value (in which case we consider that a variable holding an object is a ...
Danail Nachev's user avatar
8 votes
3 answers
23k views

I'm writing some script now and I have a problem when trying to negate boolean inside a function. I mean this: var test = true; function changeThisBoolPlease(asd){ asd=!asd; } alert(test); ...
adam's user avatar
  • 405
3 votes
1 answer
8k views

I would like to create a single function to toggle any boolean of my code, but I'm not able to get the expected result : function toggle(x){ x=!x; } var test=false; toggle(test); alert(test); Why ...
user avatar
-1 votes
4 answers
6k views

Why doesn't this work and is there any way to get it to work? Im pretty sure it doesn't work because of variable scoping in javascript, but I can't think of any ways to get it to work. Code var x = 5; ...
Daniel Kobe's user avatar
  • 9,885
-1 votes
3 answers
3k views

I want to use map method on array with callback to another function. Everything seems to be working fine, but at the end returning values are not affected. I don't know what seems to be the problem. ...
norbidrak's user avatar
  • 473
0 votes
1 answer
5k views

I expected the first console.log to be [0,10,20,30] and the second to be [0,100,20,30]: var arr = [0,10,20,30] console.log(arr) arr.forEach(each) console.log(arr) function each(data,index) {...
Phillip Senn's user avatar
  • 47.8k
4 votes
4 answers
222 views

I am looking at this piece of code from John Resig's website. What I don't understand is when the ninja object is set to an empty object, the yell method is still available to samurai. Is it ...
learner's user avatar
  • 61
1 vote
2 answers
1k views

An example, I declared an object json and in a for loop, I change the json's value and push it into the list2, But It didn't output the value what I expected. var json = { value: '', text: '',...
afraid.jpg's user avatar
  • 1,185
0 votes
1 answer
759 views

This is more of a curiosity thing than a code not working thing. It would seem that when using Async Functions in JS, mutating passed in variables works as one would expect, while reassigning them ...
Murray Gudesblat's user avatar
1 vote
1 answer
319 views

Hi I have a question about this code, why does it prints "Wild" instead of "Tabby" var cat = { name: "Athena" }; function swap(feline) { feline.name = "Wild"; feline = ...
Ivan Surya Hutomo's user avatar
0 votes
0 answers
485 views

In my code snippet I have an object "cat" that I store into two variables "Pelle" and "Kalle". If I change the name of Pelle, it also changes the name of Kalle. I believe it has to do with them being ...
chichi's user avatar
  • 213
2 votes
5 answers
133 views

I have looked online about changing variables in an function but still doesn't work. I'm trying to change the global variable in a function. An object with numbers are multiplied by each other. The ...
user3210416's user avatar
0 votes
2 answers
188 views

var foo = 0; var bar = 0; var arr1 = [1, 2, 3, 4, 5]; var arr2 = [6, 7, 8, 9, 10]; function getSum(arr, sum) { sum = arr.reduce(function(accum, val) { return accum += val; }, 0) } ...
user avatar
2 votes
2 answers
96 views

Since arrays are passed to functions by reference, when I set the array to be equal to something else inside a function, and try to log it outside of the function again, why does the value remain the ...
DwayneCena's user avatar
2 votes
3 answers
79 views

I'm trying to store the objects into Javascript array. var res=[ {name:'Alex',place:'US',age:20}, {name:'Jason',place:'Canada',age:25} ]; var obj={}; var data=[]; for ( let i in res){ ...
Vasu Ch's user avatar
  • 305

15 30 50 per page
1
2 3 4 5
11