For smart Primates & ROBOTS (oh and ALIENS ).

Blogroll

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:

0 comments:

Post a Comment

How to make center align child div

 How to make center align child div?   Suppose you have 2 Div tag. And want the make inner tag center <div id="d1">      ...

Ads Inside Post

Powered by Blogger.

Arsip