JavaScript, Deconstructed: Variables

Variables

JavaScript, Deconstructed: Variables

Before we dive into JavaScript programming, what it is or isn't, what it does or does not do let's a give a little overview of what computer programming is.

Computer Programming

Computer programming or coding is the writing of sequences of instructions called programs or applications that computers can follow to accomplish a task.

A computer is an electronic device for storing and processing data.

A sequence is a particular order in which related things follow each other.

Instructions - Detailed information(facts) about how something should be done or operated.

An electronic device is hardware whose function is to control the flow of electrical energy for the purpose of processing.

Computer processing is the actions that a computer takes to execute commands a user makes.

An example of a popular program commonly used by individuals and small to large companies alike is a web browser.

Web browser- A web browser is an application for accessing websites.

Web - This is a shortened version of The World Wide Web which can also be called WWW or W3. This refers to public websites or pages that users can access on their local computers and other devices through the internet.

A website is a set of related web pages located under a single domain name, typically produced by a single person or organization.

The internet is a global computer network providing a variety of information and communication facilities, consisting of interconnected networks using standardized communication protocols.

A web page is a hypertext document on the World Wide Web

A domain name is a unique, easy-to-remember address used to access websites for example google.com, x.com.

Hypertext is a software system allowing extensive cross-referencing between related sections of text and associated graphic material.

A computer network is a system that connects two or more computing devices for transmitting and sharing information.

Information and communication facilities are physical installations which transmit, receive and/or relay data.


Variables

Variables in JavaScript programming are containers for storing data. This data can then later be used to perform a task. Variables can hold data like a string (eg "House", 'Shoe') and numbers (23,45,99). Strings can be identified using single quotes (' ') or double quotes (" ").

String is any text inside double or single quotes.

In JavaScript the act of creating a variable is called declaring a variable. So when I create a variable with name houseName I have declared this variable which is going to be used to store some information now or at a later date.

In JavaScript we declare variables in three ways by using the keywords let, var and const using a name value pairing convention. In the code below we can see that houseName is the name and 'House' is the value which this time is a string.

let houseName = 'House'
var houseName = 'House'
const houseName = 'House'

console.log(houseName)

The equal to \= sign here is not the same as the one used in mathematics to indicate equality. It just shows that a data type has been assigned to the variable in question so the variable can act as a container for this data type.

A data type describes the different types of data that variables can store.

Copy and paste the code below on onecompiler.com to see the results. Click on the run button to see the output of the code.

const houseName = 'House'

console.log(houseName)

Console.log() is a JavaScript method used to display information in the console.

A JavaScript method enables programmers to perform certain actions on objects.

A console in JavaScript allows you to display the output of your code so you can have a visual feedback of what's happening under the hood so to speak. The environment in which the console runs is the web browser.

Output is any information that a computer application produces. This could be sounds, pictures, text or motion on a screen.

To run a piece of code means to cause your instructions (program or application) to be carried out.

An object in programming is a collection of related properties. The properties are divided into or made up of key and value pairs. The code below illustrates one way of declaring an object.

const objectName = {
   key1: value1,
   key2: value2
}


const Car = {
    color: "red"
    brand: "Hyundai"
{

const human = {
    height: 198
    weight: 120
{

//