Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to define DO NOTHING in JavaScript

Tags:

javascript

I am displaying a confirm box in my app. When the user clicks on Okay, I close the window
when user clicks on Cancel, I want to do nothing but stay on the same page.

What should I write in place of DO_NOTHING?

    <a href="#" onclick="confirm('Do you wan to close the application ?')?window.close():DO_NOTHING')">Close the application ?</a> 

If I keep it empty it does not work. If I write any random string it works but displays string undefined error.

like image 626
Ajinkya Avatar asked Jun 21 '11 10:06

Ajinkya


People also ask

What is nothing in JavaScript?

JavaScript has two values which mean "nothing", undefined and null . undefined has a much stronger "nothing" meaning than null because it is the default value of every variable. No variable can be null unless it is set to null , but variables are undefined by default.

What does () => mean in JavaScript?

It's a new feature that introduced in ES6 and is called arrow function. The left part denotes the input of a function and the right part the output of that function.

What is a do nothing function?

A function that does nothing (yet) is an indicator that something should be done, but hasn't been implemented yet. Follow this answer to receive notifications. answered Jun 27, 2016 at 13:42. Ivan Rubinson.


1 Answers

Try using void(0)

<a href="#" onclick="confirm('Do you wan to close the application ?')?window.close():void(0)')">Close the application ?</a>
like image 58
Matt MacLean Avatar answered Nov 12 '22 07:11

Matt MacLean