Exploring JavaScript Basics and Understanding Variables

·

3 min read

  • JavaScript is a high-level, interpreted programming language primarily used for building interactive websites and web applications.

  • It was created by Brendan Eich in 1995 and is now one of the most widely used programming languages.

  • JavaScript runs on the client side (web browsers) as well as the server side (with the help of frameworks like Node.js).

  • It is known for its versatility and ability to add interactivity to web pages by manipulating HTML and CSS.

Getting familiar

To start, we as to use the modern javascript featured in our codebase, use a special phrase called "use strict". It's like a magic spell which makes our code better and reliable. We use it at the beginning of our code to tell Javascript to treat everything as latest practices. It's like you having the newest and the coolest tools.

We can make objects show on the screen by using JavaScript. Typically, we use the "alert" command to display messages in a web browser as an alert on top. But since we're developers and will be mostly using Node.js, we have a unique method for displaying messages, we use a tool called "console" to create private messages that are only visible to us. It's like leaving ourselves notes while programming!

Types and Variables:

Let's now discuss the extremely crucial idea of variables. Consider them as unique containers that may carry various items. We are able to place words, figures, and even complete sentences inside of these containers! To save data and use it later in our code, we use variables.

Imagine, for instance, that the variable "name" contains the name "Devashish." We can have a variable named "isLoggedIn" that can either hold true or false, and another variable called "age" that can hold the number 20.

Datatypes

We have several different types of values in JavaScript. Numbers are similar to the maths we learn in school, thus we have numbers. We have strings, which are quotation-marked versions of words or sentences. We also have booleans, which are statements that are either true or false. There's more, too! Null denotes anything being empty or not yet having a value. Undefined, on the other hand, denotes the absence of any value for something. We also have artefacts that can bind a wide variety of things together and symbols for individuality.

Checking types

At times, we're interested in the kind of value a variable has. The command "typeof" in JavaScript allows us to ask it a magical inquiry. It's similar to asking a hidden oracle what our variables' characteristics are, and getting a response!

JavaScript will inform us it is a number if we use "typeof" on the variable "age," for instance. But when we apply "typeof" to "null," it informs us that it is an object. That's intriguing, isn't it? There might be amusing shocks even in the realm of coding!

Always keep in mind that variables are like unique containers that store various things, and "typeof" enables us to learn more about them.

I hope you found this blog helpful and engaging. I would love to hear your feedback and any suggestions you may have for future topics.