{"id":2190,"date":"2022-04-12T16:00:09","date_gmt":"2022-04-12T16:00:09","guid":{"rendered":"https:\/\/mdr.foobrdigital.com\/?p=2190"},"modified":"2022-04-12T16:00:09","modified_gmt":"2022-04-12T16:00:09","slug":"javascript-example","status":"publish","type":"post","link":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/2022\/04\/12\/javascript-example\/","title":{"rendered":"JavaScript Example"},"content":{"rendered":"\n<ol><li>JavaScript Example<\/li><li>Within body tag<\/li><li>Within head tag<\/li><\/ol>\n\n\n\n<p>Javascript example is easy to code. JavaScript provides 3 places to put the JavaScript code: within body tag, within head tag and external JavaScript file.<\/p>\n\n\n\n<p>Let\u2019s create the first JavaScript example.<a href=\"https:\/\/www.javatpoint.com\/javascript-example#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/javascript-example#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/javascript-example#\"><\/a><\/p>\n\n\n\n<ol><li><strong>&lt;<\/strong><strong>script<\/strong>&nbsp;type=&#8221;text\/javascript&#8221;<strong>&gt;<\/strong>&nbsp;&nbsp;<\/li><li class=\"\">document.write(&#8220;JavaScript&nbsp;is&nbsp;a&nbsp;simple&nbsp;language&nbsp;for&nbsp;javatpoint&nbsp;learners&#8221;);&nbsp;&nbsp;<\/li><li><strong>&lt;\/<\/strong><strong>script<\/strong><strong>&gt;<\/strong>&nbsp;&nbsp;<\/li><\/ol>\n\n\n\n<p><\/p>\n\n\n\n<p>The&nbsp;<strong>script<\/strong>&nbsp;tag specifies that we are using JavaScript.<\/p>\n\n\n\n<p>The&nbsp;<strong>text\/javascript<\/strong>&nbsp;is the content type that provides information to the browser about the data.<\/p>\n\n\n\n<p>The&nbsp;<strong>document.write()<\/strong>&nbsp;function is used to display dynamic content through JavaScript. We will learn about document object in detail later.<\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">3 Places to put JavaScript code<\/h2>\n\n\n\n<ol><li>Between the body tag of html<\/li><li>Between the head tag of html<\/li><li>In .js file (external javaScript)<\/li><\/ol>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">1) JavaScript Example : code between the body tag<\/h2>\n\n\n\n<p>In the above example, we have displayed the dynamic content using JavaScript. Let\u2019s see the simple example of JavaScript that displays alert dialog box.<a href=\"https:\/\/www.javatpoint.com\/javascript-example#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/javascript-example#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/javascript-example#\"><\/a><\/p>\n\n\n\n<ol><li><strong>&lt;<\/strong><strong>script<\/strong>&nbsp;type=&#8221;text\/javascript&#8221;<strong>&gt;<\/strong>&nbsp;&nbsp;<\/li><li class=\"\">&nbsp;alert(&#8220;Hello&nbsp;Javatpoint&#8221;);&nbsp;&nbsp;<\/li><li><strong>&lt;\/<\/strong><strong>script<\/strong><strong>&gt;<\/strong>&nbsp;&nbsp;<\/li><\/ol>\n\n\n\n<p><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">2) JavaScript Example : code between the head tag<\/h2>\n\n\n\n<p>Let\u2019s see the same example of displaying alert dialog box of JavaScript that is contained inside the head tag.<\/p>\n\n\n\n<p>In this example, we are creating a function msg(). To create function in JavaScript, you need to write function with function_name as given below.<\/p>\n\n\n\n<p>To call function, you need to work on event. Here we are using onclick event to call msg() function.<a href=\"https:\/\/www.javatpoint.com\/javascript-example#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/javascript-example#\"><\/a><a href=\"https:\/\/www.javatpoint.com\/javascript-example#\"><\/a><\/p>\n\n\n\n<ol><li><strong>&lt;<\/strong><strong>html<\/strong><strong>&gt;<\/strong>&nbsp;&nbsp;<\/li><li class=\"\"><strong>&lt;<\/strong><strong>head<\/strong><strong>&gt;<\/strong>&nbsp;&nbsp;<\/li><li><strong>&lt;<\/strong><strong>script<\/strong>&nbsp;type=&#8221;text\/javascript&#8221;<strong>&gt;<\/strong>&nbsp;&nbsp;<\/li><li class=\"\">function&nbsp;msg(){&nbsp;&nbsp;<\/li><li>&nbsp;alert(&#8220;Hello&nbsp;Javatpoint&#8221;);&nbsp;&nbsp;<\/li><li class=\"\">}&nbsp;&nbsp;<\/li><li><strong>&lt;\/<\/strong><strong>script<\/strong><strong>&gt;<\/strong>&nbsp;&nbsp;<\/li><li class=\"\"><strong>&lt;\/<\/strong><strong>head<\/strong><strong>&gt;<\/strong>&nbsp;&nbsp;<\/li><li><strong>&lt;<\/strong><strong>body<\/strong><strong>&gt;<\/strong>&nbsp;&nbsp;<\/li><li class=\"\"><strong>&lt;<\/strong><strong>p<\/strong><strong>&gt;<\/strong>Welcome&nbsp;to&nbsp;JavaScript<strong>&lt;\/<\/strong><strong>p<\/strong><strong>&gt;<\/strong>&nbsp;&nbsp;<\/li><li><strong>&lt;<\/strong><strong>form<\/strong><strong>&gt;<\/strong>&nbsp;&nbsp;<\/li><li class=\"\"><strong>&lt;<\/strong><strong>input<\/strong>&nbsp;type=&#8221;button&#8221;&nbsp;value=&#8221;click&#8221;&nbsp;onclick=&#8221;msg()&#8221;<strong>\/&gt;<\/strong>&nbsp;&nbsp;<\/li><li><strong>&lt;\/<\/strong><strong>form<\/strong><strong>&gt;<\/strong>&nbsp;&nbsp;<\/li><li class=\"\"><strong>&lt;\/<\/strong><strong>body<\/strong><strong>&gt;<\/strong>&nbsp;&nbsp;<\/li><li><strong>&lt;\/<\/strong><strong>html<\/strong><strong>&gt;<\/strong>&nbsp;&nbsp;<\/li><\/ol>\n","protected":false},"excerpt":{"rendered":"<p>JavaScript Example Within body tag Within head tag Javascript example is easy to code. JavaScript provides 3 places to put the JavaScript code: within body tag, within head tag and external JavaScript file. Let\u2019s create the first JavaScript example. &lt;script&nbsp;type=&#8221;text\/javascript&#8221;&gt;&nbsp;&nbsp; document.write(&#8220;JavaScript&nbsp;is&nbsp;a&nbsp;simple&nbsp;language&nbsp;for&nbsp;javatpoint&nbsp;learners&#8221;);&nbsp;&nbsp; &lt;\/script&gt;&nbsp;&nbsp; The&nbsp;script&nbsp;tag specifies that we are using JavaScript. The&nbsp;text\/javascript&nbsp;is the content type that provides [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[429],"tags":[],"_links":{"self":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/posts\/2190"}],"collection":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/comments?post=2190"}],"version-history":[{"count":0,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/posts\/2190\/revisions"}],"wp:attachment":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/media?parent=2190"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/categories?post=2190"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/tags?post=2190"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}