
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
Setting a default variable value to undefined in a function - JavaScript?
Let’s say we are passing the following values to a function −
300 undefined
Example
We will now set the default value. Following is the code −
function showValue(value) { if (value===undefined) { value=100000; } else { value=value; } return value; } console.log("The value="+showValue(300)); console.log("The value="+showValue(undefined));
To run the above program, you need to use the following command −
node fileName.js.
Here, my file name is demo246.js.
Output
This will produce the following output on console −
PS C:\Users\Amit\javascript-code> node demo246.js The value=300 The value=100000
- Related Articles
- Set a default value for the argument to cover undefined errors while calling a function in JavaScript
- How to set a default parameter value for a JavaScript function?
- How to check for “undefined” variable in JavaScript?
- Tkinter Spinbox Widget Setting Default Value
- How to pass the value 'undefined' to a function with multiple parameters in JavaScript?
- Replace a value if null or undefined in JavaScript?
- How to use a function for default value in MySQL?
- How to change the value of a global variable inside of a function using JavaScript?
- How to define global variable in a JavaScript function?
- What is the default value of a local variable in Java?\n
- How can we assign a function to a variable in JavaScript?
- Assigning function to variable in JavaScript?
- How to execute a JavaScript function using its name in a variable?
- Increment multiple Timestamp values by setting the incremented value in a user-defined variable in SQL
- How to load a JavaScript function using the variable name?

Advertisements