EzDevInfo.com

function interview questions

Top function frequently asked interview questions

"Parameter" vs "Argument" [duplicate]

Possible Duplicate:
Arguments or parameters?

I got "Parameter" and "Argument" kind of mixed up and did not really pay attention to when to use one and when to use the other. Can you please tell me? Thanks.


Source: (StackOverflow)

What do the parentheses around a function name mean?

In one of my project source files, I found this C function definition:

int (foo) (int *bar)
{
    return foo (bar);
}

Note: there is no asterisk next to foo, so it's not a function pointer. Or is it? What is going on here with the recursive call?


Source: (StackOverflow)

Advertisements

What is the difference between call and apply?

What is the difference between using call and apply to invoke a function?

var func = function(){
  alert('hello!');
};

func.apply();

vs

func.call();

Are there performance differences between the two methods? When is it best to use call over apply and vice versa?


Source: (StackOverflow)

Simplest/Cleanest way to implement singleton in JavaScript?

What is the simplest/cleanest way to implement singleton pattern in JavaScript?


Source: (StackOverflow)

strdup() - what does it do in C?

What is the purpose of the strdup() function in C?


Source: (StackOverflow)

Arguments or parameters? [duplicate]

This question already has an answer here:

I often find myself confused with how the terms 'arguments' and 'parameters' are used. They seem to be used interchangeably in the programming world.

What's the correct convention for their use?


Source: (StackOverflow)

How do you pass a function as a parameter in C?

I want to create a function that performs a function passed by parameter on a set of data. How do you pass a function as a parameter in C?


Source: (StackOverflow)

What is the naming convention in Python for variable and function names?

Coming from a C# background the naming convention for variables and method names are usually either CamelCase or Pascal Case:

// C# example
string thisIsMyVariable = "a"
public void ThisIsMyMethod()

In Python, I have seen the above but I have also seen underscores being used:

# python example
this_is_my_variable = 'a'
def this_is_my_function():

Is there a more preferable, definitive coding style for Python?


Source: (StackOverflow)

JavaScript variable number of arguments to function

Is there a way to allow "unlimited" vars for a function in JavaScript?

Example:

load(var1, var2, var3, var4, var5, etc...)
load(var1)

Source: (StackOverflow)

Is there a better way to do optional function parameters in Javascript?

I've always handled optional parameters in Javascript like this:

function myFunc(requiredArg, optionalArg){
  optionalArg = optionalArg || 'defaultValue';

  //do stuff

}

Is there a better way to do it?

Are there any cases where using || like that is going to fail?


Source: (StackOverflow)

Submit form on pressing Enter with AngularJS

In this particular case, what options do I have to make these inputs call a function when I press Enter?

// HTML view //
<form>
    <input type="text" ng-model="name" <!-- Press ENTER and call myFunc --> />
    <br />
    <input type="text" ng-model="email" <!-- Press ENTER and call myFunc --> />
</form>

// Controller //
.controller('mycontroller', ['$scope',function($scope) {
    $scope.name = '';
    $scope.email = '';
    // Function to be called when pressing ENTER
    $scope.myFunc = function() {
       alert('Submitted');
    };
}])

Source: (StackOverflow)

Set a default parameter value for a JavaScript function

I would like a JavaScript function to have optional arguments which I set a default on, which gets used if the value isn't defined. In Ruby you can do it like this:

def read_file(file, delete_after = false)
  # code
end

Does this work in JavaScript?

function read_file(file, delete_after = false) {
  // Code
}

Source: (StackOverflow)

How to get a function name as a string in Python?

In Python, how do I get a function name as a string without calling the function?

def my_function():
    pass

print get_function_name_as_string(my_function) # my_function is not in quotes

should output "my_function".

Is this available in python? If not, any idea how to write get_function_name_as_string in Python?


Source: (StackOverflow)

Difference between a method and a function

Can someone provide a simple explanation of methods vs. functions?


Source: (StackOverflow)