1

Just tried this code in JSFiddle (learning JS atm):

var checkArrayForDuplicates = new function(arrayToCheck, content) {
    alert(arrayToCheck);
}

var numbers = new Array(1, 2, 3, 4, 5, 5);    
checkArrayForDuplicates(numbers, 5);

But arrayToCheck (numbers) is always undefined inside the function. :(

2 Answers 2

5

Your function definition is not correct, change to:

var checkArrayForDuplicates = function(arrayToCheck, content) {
    alert(arrayToCheck);
}

You have put new in your definition in front of the function name, and this is not the right syntax to use with new.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you. I think this is the stuff I have to deal with when moving from Java and C# to JS.
@mosquito87 You are welcome, glad I could help. I worked with both C# and Java and still, but JavaScript (in my opinion) is much more powerful and flexible.
1

Remove the new word. It should just be:

= function () {}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.