{"id":4433,"date":"2016-03-02T09:03:51","date_gmt":"2016-03-02T09:03:51","guid":{"rendered":"http:\/\/www.hostingnotes.com\/?p=4433"},"modified":"2017-10-09T14:08:36","modified_gmt":"2017-10-09T14:08:36","slug":"online-javascript-manual-variables-and-javascript-methods","status":"publish","type":"post","link":"https:\/\/www.webdevelopersnotes.com\/online-javascript-manual-variables-and-javascript-methods","title":{"rendered":"Online JavaScript Manual &#8211; Variables and JavaScript methods"},"content":{"rendered":"<p>Till now we&#8217;ve looked at two important methods, the alert() method of the window object and write() of document object. You&#8217;ve also seen how text or numbers can be passed to these methods.<\/p>\n<p>Let&#8217;s consider a situation where you plan to display the name of the visitor on the page. To do this you would first have to get the visitor&#8217;s name (we&#8217;ll shortly see how to achieve this), store it in a variable and send the result to the document.write() method. Here we&#8217;ll examine how we can pass variables to JavaScript methods.<\/p>\n<pre class=\"small-text\">\r\ndocument.write(\"Your name is \" + vis_name);\r\n<\/pre>\n<p>We&#8217;ve assumed that the visitor&#8217;s name is stored in a variable called <em>vis_name<\/em>. Note how the variable is written outside the quotes of the write() method. If this variable was included in the quotes, JavaScript would have written <strong>vis_name<\/strong> instead of the name of the visitor. Similarly, for the alert() method, we would pass the value as:<\/p>\n<pre class=\"small-text\">\r\nalert(\"Welcome \" + vis_name + \"\\nHow are we today?\");\r\n<\/pre>\n<p>Remember, a variable should be placed outside the quotes to display its value.<\/p>\n<div class=\"pagenav\">\n<ul>\n<li><a href=\"\/\/www.webdevelopersnotes.com\/javascript-increment-and-decrement-operators-operator-precedence\" title=\"Operator precedence in javascript - The increment and decrement javascript operators\">&lt; Back<\/a><\/li>\n<li><a href=\"\/\/www.webdevelopersnotes.com\/javascript-tutorial\" title=\"JavaScript tutorial\">1<\/a><\/li>\n<li>&#8230;<\/li>\n<li><a href=\"\/\/www.webdevelopersnotes.com\/javascript-event-handlers-part-1\" title=\"Javascript onmouseover and javascript onmouseout event handlers\">10<\/a><\/li>\n<li>&#8230;<\/li>\n<li><a href=\"\/\/www.webdevelopersnotes.com\/online-javascript-manual-variables-and-javascript-methods\" title=\"Online javascript manual - variables and javascript methods\" class=\"thispage\">18<\/a><\/li>\n<li>&#8230;<\/li>\n<li><a href=\"\/\/www.webdevelopersnotes.com\/javascript-if-statement\" title=\"Javascript IF statement\">20<\/a><\/li>\n<li>&#8230;<\/li>\n<li><a href=\"\/\/www.webdevelopersnotes.com\/changing-images-on-mouseover-using-javascript\" title=\"Changing images on mouseover using Javascript\">30<\/a><\/li>\n<li>&#8230;<\/li>\n<li><a href=\"\/\/www.webdevelopersnotes.com\/javascript-errors-understanding-and-correcting\" title=\"Understanding and correcting javascript errors\">Next &gt;<\/a><\/li>\n<\/ul>\n<\/div>\n","protected":false},"excerpt":{"rendered":"Till now we&#8217;ve looked at two important methods, the alert() method of the window object and write() of document object. You&#8217;ve also seen how text or numbers can be passed to these methods. Let&#8217;s consider a situation where you plan to display the name of the visitor on the page. To do this you would [&hellip;]","protected":false},"author":1,"featured_media":15659,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[56],"tags":[],"class_list":["post-4433","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-javascript"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.webdevelopersnotes.com\/wp-json\/wp\/v2\/posts\/4433","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.webdevelopersnotes.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.webdevelopersnotes.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.webdevelopersnotes.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.webdevelopersnotes.com\/wp-json\/wp\/v2\/comments?post=4433"}],"version-history":[{"count":0,"href":"https:\/\/www.webdevelopersnotes.com\/wp-json\/wp\/v2\/posts\/4433\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.webdevelopersnotes.com\/wp-json\/wp\/v2\/media\/15659"}],"wp:attachment":[{"href":"https:\/\/www.webdevelopersnotes.com\/wp-json\/wp\/v2\/media?parent=4433"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.webdevelopersnotes.com\/wp-json\/wp\/v2\/categories?post=4433"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.webdevelopersnotes.com\/wp-json\/wp\/v2\/tags?post=4433"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}