Values and Operators in JS

Photo by James Harrison on Unsplash

JavaScript is an infamous programming language, usually confused for 'Java’. These are two different languages altogether, connected in no way other than their first four letters.

Values

Anything in your computer is data, let it be an image of you in Disneyland, a game or a document. All the data is stored in bits(small fragments of data), consisting of zeroes and ones.

The first programs were written in 0s and 1s. But we have come a far way from that, today programming is as easy as it can be, making JavaScript (JS) a common choice, as it gives one more control. Which is both good and bad.

Let’s jump to values in JS. There are 4 types of Data types (Actually 6, but for the sake of simplicity, let’s learn these 4 first). Namely — Numbers, String, Boolean and Undefined

1- Numbers — As simple as it sounds, it stores the value of data in form of numbers, both whole and decimal. It also holds negative and positive values between the range of -infinity & infinity.

var a = 14;
var b = 56.27;
var c = -45;
// in the above code snippets, there are three data, stored by the // name of 'a, b & c' having a value attached to them, i.e, 15,
// 56.27 & -45 respectively. All these values are number of NUMBER // DATATYPE.

2- String — String values are anything that is put in any of these three quotes, which can hold value of any length, word, letters and sentences:

  • ``- Backticks- Includes features to include JS code inside it
  • ‘ ’- Single quotes- Normal way of declaring String
  • “ ”- Double quotes- Same as above, matter of personal preference
var name = `Dash`;
var job = 'Developer';
var sentence = "Dash is a web developer."
// as you see I have used three different types of quote marks, but // all of them essentially mean that the data type of the value is // of STRING DATATYPE

3- Boolean — Boolean are of two types; true and false.

var somethingRight = true;
var somethingWrong = false;
// the above value of data are BOOLEAN DATATYPE
// they can't hold any other value, just true and false.

4- Undefined — Undefined datatype are for those values whose type we don’t know, whether it is number, string or boolean. It is yet to be defined.

Undefined value doesn’t do anything, and has very few use. Null is an empty value, which amounts to, well, null. There is no much difference between the two in practical ways, these are just the children of the design of the language when created.

var universe = null;// the variable universe doesn't contain anything. It is NULL.
// undefined values appear when a code snippet has to give some
// values but doesn't know what value to give.

Operators

Operators are like our Mothers. They work with some inputs (operands) and give us the output, just like our Mothers make us our favourite dishes using various ingredients.

There are three kinds of operators;

  • Unary operator- These operators work on one operand, such as typeof()
typeof('Hello World!');// the output will be String, why? Because it is wrapped inside 
// single quotes. Remember from the previous section? Awesome.
// it is just one example of unary operators, there are a few others // too.
  • Binary operators- These work on 2 operands, such as +, -, /, *, %
console.log( 20 + 30 );// output will 50. As you see, '+' is a binary operator, working on // two operands (20 & 30). 
  • Ternary operator- There is only one of these. It works with three operands.

(conditon) ? statement-if-true: statement-if-false.

So, to sum up, JS has various different kinds of data, to help us write a program. There are many different operators to change the values stored, assigning them new values and such

That is it, for details of the challenge. Click Here. This article was inspired by Eloquent JavaScript- Chapter 1 by Marijn Haverbeke.

--

--

--

Dreamer | Coder | Designer | Podcaster | Blogger

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Tuple-Union conversions in TypeScript

How to develop a Heart rate reader application

Numeric Operators in JavaScript

Color Palettes Range

International phone number with Dial Code and Flag on HTML input tag

GSoC 2018: Interactive Demo Apps: Behind the Scenes & Under the Hood

TypeScript with Babel: A Beautiful Marriage

Creative Coding Week 11: Connecting Arduino to P5

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Sudesh Kumar Das

Sudesh Kumar Das

Dreamer | Coder | Designer | Podcaster | Blogger

More from Medium

Escaping Tutorial Hell

JavaScript Overview Part 2 — Values and data types

Object-Oriented Programming (OOP)

Frequency Counter Patterns in Algorithms…