For smart Primates & ROBOTS (oh and ALIENS ).

Showing posts with label autoexecute. Show all posts
Showing posts with label autoexecute. Show all posts

Saturday, November 30, 2024

Auto execute code in javascript

How to write auto execute javascript code ?


We can achieve it by 2 method.

1- Standard auto execute function.

2- Arrow function.


Standard auto execute function.


<script>
(function() {
  const iamvar1= 'Iam var 1';
  console.log('Auto Execute 1 function');
})();
</script>


Arrow function.

<script>
(()=> {
  const iamvar2= 'Iam var 2';
  console.log('Auto Execute 2 function');
})();

</script>

Share:

Ads Inside Post

Powered by Blogger.

Archive