{"id":41715,"date":"2025-10-17T04:17:38","date_gmt":"2025-10-17T01:17:38","guid":{"rendered":"https:\/\/coma.lv\/2025\/10\/17\/what-is-javascript\/"},"modified":"2025-10-17T04:17:38","modified_gmt":"2025-10-17T01:17:38","slug":"what-is-javascript","status":"publish","type":"post","link":"https:\/\/coma.lv\/en\/2025\/10\/17\/what-is-javascript\/","title":{"rendered":"What Is JavaScript"},"content":{"rendered":"\n<p style=\"text-align: left;\">JavaScript is a programming language built into browsers that makes web pages &#8220;alive&#8221;. Programs in this language are called scripts. In the browser they are attached to HTML and run right after the page loads. JS lets you add dynamic elements to a site: sliders, pop-up windows, buttons, interactive forms and other interface elements.<\/p>\n<h2 style=\"text-align: left;\" data-start=\"680\" data-end=\"705\">JavaScript in WordPress<\/h2>\n<p style=\"text-align: left;\">WordPress themes and plugins actively use JavaScript to create interactive and dynamic elements. The most common combination is:<\/p>\n<ul style=\"text-align: left;\">\n<li>Vanilla JS (plain JavaScript without libraries)<\/li>\n<li>AJAX for dynamic requests without reloading the page<\/li>\n<li>jQuery (for backward compatibility and older themes)<\/li>\n<li>Modern frameworks in advanced themes: React, Vue.js, Alpine.js<\/li>\n<\/ul>\n<p style=\"text-align: left;\" data-start=\"1115\" data-end=\"1201\">JavaScript can be added to a theme or plugin using standard WordPress functions:<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n\/\/ \u0420\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u044f \u0438 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0441\u043a\u0440\u0438\u043f\u0442\u0430\r\nwp_register_script( &amp;#039;custom-js&amp;#039;, get_template_directory_uri() . &amp;#039;\/js\/custom.js&amp;#039;, array(&amp;#039;jquery&amp;#039;), null, true );\r\nwp_enqueue_script( &amp;#039;custom-js&amp;#039; );\r\n<\/pre>\n<div class=\"contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary\" style=\"text-align: left;\">\n<div class=\"sticky top-9\">\n<div class=\"absolute end-0 bottom-0 flex h-9 items-center pe-2\">\n<div class=\"bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs\">\n<p data-start=\"1398\" data-end=\"1587\"><strong data-start=\"1398\" data-end=\"1408\">Tip:<\/strong> inserting JS directly into theme files (for example, header.php or footer.php) is not recommended. It is better to use <code data-start=\"1490\" data-end=\"1511\">wp_enqueue_script()<\/code> and, if necessary, <code data-start=\"1532\" data-end=\"1554\">wp_localize_script()<\/code> to pass data from PHP to JS.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\">\n<h2 data-start=\"1594\" data-end=\"1624\">Organizing Scripts in a Theme<\/h2>\n<p data-start=\"1626\" data-end=\"1825\">Many themes contain a separate <code data-start=\"1663\" data-end=\"1668\">\/js<\/code> folder where all the JavaScript files are stored. Scripts are loaded only where they are needed. This speeds up page loading and prevents unnecessary script loading.<\/p>\n<p data-start=\"1827\" data-end=\"1849\">Example of a theme structure:<\/p>\n<pre class=\"brush: css; title: ; notranslate\" title=\"\">\r\n\/wp-content\/themes\/my-theme\/\r\n\u251c\u2500\u2500 js\/\r\n\u2502   \u251c\u2500\u2500 main.js\r\n\u2502   \u251c\u2500\u2500 slider.js\r\n\u2502   \u2514\u2500\u2500 popup.js\r\n\u251c\u2500\u2500 style.css\r\n\u251c\u2500\u2500 functions.php\r\n\u2514\u2500\u2500 index.php\r\n<\/pre>\n<\/div>\n<\/div>\n<h2 style=\"text-align: left;\">Standard WordPress Libraries<\/h2>\n<p style=\"text-align: left;\">WordPress includes several libraries that you can use in your themes and plugins:<\/p>\n<ul style=\"text-align: left;\">\n<li>jQuery \u2014 for backward compatibility<\/li>\n<li>Underscore.js \u2014 utility functions<\/li>\n<li>Backbone.js \u2014 for building structured client-side applications<\/li>\n<li>wp.i18n \u2014 for internationalization<\/li>\n<li>wp.apiFetch \u2014 for AJAX requests to the REST API<\/li>\n<\/ul>\n<p style=\"text-align: left;\">Example of loading a built-in library:<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\nwp_enqueue_script( &amp;#039;jquery&amp;#039; ); \/\/ \u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 jQuery\r\n<\/pre>\n<h2 style=\"text-align: left;\">Conclusion<\/h2>\n<p style=\"text-align: left;\" data-start=\"2973\" data-end=\"3311\">JavaScript remains the main tool for building interactive WordPress sites. Modern themes use a combination of vanilla JS, AJAX and frameworks. Well-organized and correctly enqueued JS makes a site faster, more convenient and more modern.<\/p>\n<hr \/>\n<p style=\"text-align: left;\"><em>Our specialization is WordPress website development and maintenance. Contact us for a free consultation \u2014 <a href=\"mailto:vadim@coma.lv\">vadim@coma.lv<\/a>, <a href=\"tel:+37129394520\">+371 29394520<\/a><\/em><\/p>\n<hr \/>\n","protected":false},"excerpt":{"rendered":"<p>JavaScript is a programming language built into browsers that makes web pages &#8220;alive&#8221;. Programs in this language are called scripts. In the browser they are attached to HTML and run right after the page loads. JS lets you add dynamic elements to a site: sliders, pop-up windows, buttons, interactive forms and other interface elements. JavaScript [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":37616,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1225,1405],"tags":[],"class_list":["post-41715","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-wordpress","category-terms"],"_links":{"self":[{"href":"https:\/\/coma.lv\/en\/wp-json\/wp\/v2\/posts\/41715","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/coma.lv\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/coma.lv\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/coma.lv\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/coma.lv\/en\/wp-json\/wp\/v2\/comments?post=41715"}],"version-history":[{"count":0,"href":"https:\/\/coma.lv\/en\/wp-json\/wp\/v2\/posts\/41715\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/coma.lv\/en\/wp-json\/wp\/v2\/media\/37616"}],"wp:attachment":[{"href":"https:\/\/coma.lv\/en\/wp-json\/wp\/v2\/media?parent=41715"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/coma.lv\/en\/wp-json\/wp\/v2\/categories?post=41715"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/coma.lv\/en\/wp-json\/wp\/v2\/tags?post=41715"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}