Call to a JS function
alertStatement()
Function Definition
function alertStatement(link) { if (link) { alert('A'); } if (link!=null) { alert('B'); } }
Both of these statements are working fine in Windows Env with Tomcat, but none of them execute it on production (Linux server). Is there any other way to compare variables to make it working?
I got it working using the following javascript code.
function alertStatement(link) { if (link!==undefined){ alert('A'); } }
So at last undefined worked for me , for some reason null comparison didn't work
To see if the argument has a usable value, just check if the argument is undefined. This serves two purposes. It checks not only if something was passed, but also if it has a usable value:
function alertStatement(link) { if (link !== undefined) { // argument passed and not undefined } else { // argument not passed or undefined } }
Some people prefer to use typeof like this:
function alertStatement(link) { if (typeof link !== "undefined") { // argument passed and not undefined } else { // argument not passed or undefined } }
null
is a specific value. undefined
is what it will be if it is not passed.
If you just want to know if anything was passed or not and don't care what its value is, you can use arguments.length
.
function alertStatement(link) { if (arguments.length) { // argument passed } else { // argument not passed } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With