What is JavaScript?

javascript_banner_sxve2l.png

My aim here while writing this piece is, for anyone who reads this to be able to understand what I'm trying to say. So, with that in mind and me being a newbie myself here we go.

  • It's a web based scripting language. Primarily used to manipulate the HTML of a page. So, using JavaScript you can manipulate tables, divs, fonts etc... with traditional programming functionality.
  • JavaScript is known as a client-side language, and what this means is that the changes effected to a page through JavaScript are seen only by you, the client. In other words, lets say you click on a button, and that button executes a JavaScript command which changes the background color of the website blue. That change in blue will only be seen by you, not by anyone else, and it will go away the moment you refresh. Why? Because JavaScript interacts only with you, the client, and has no interaction with the server which actually hosts the background color. Its usage are restricted to the page you are currently viewing, and your individual interactions with it. This is known generally as working on the front end.
  • On the other hand, you've got a language like Java which interacts directly with a server. So in this case, clicking a button could execute a Java method which actually goes into the server itself and changes the background color. Now the background color has actually been changed on the back-end, and everyone who visits the website will see the changed background color. This is known as server-side scripting or the back end. Java cannot directly manipulate the HTML on the page on a client-side basis.

Let's check this out. Type this on your browser console.

javascript:document.getElementsByTagName("body")[0].style.backgroundColor = "black";void(0);

Your page should now be black. This isn't a permanent change, and it only happens to you -- it'll go away on refresh. That's what JavaScript does -- it changes/serves the stuff on your screen.

image.png

Now compare that to, say, changing your password... that makes a permanent change in the back-end.

#javascript