Set a default parameter value for a JavaScript function

by Ranganathan 2012-08-28 23:29:14

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
}

Tagged in:

856
like
0
dislike
0
mail
flag

You must LOGIN to add comments