DEV Community

param-19
param-19

Posted on • Originally published at ejs-challenge.netlify.app

Introduction to Javascript

Recently, I started off on working with Javascript, after studiously trying to ignore it ( because people said a lot, and I get influenced easily ). I took to php , had decent projects and even managed to intern at a respectable institute using my knowledge. However, as the days passed, I realised something : I would have to learn and work with Javascript, sooner or later.I did do a couple of projects before, but never felt it worth it and always kept on ignoring it.

So after a year of ignorance, I got motivated enough to start working with it. It takes a great deal of hard work and self discipline to come out of your safe little bubble, and I feel lucky enough to finally come out of it. Thanks to the motivation offered by peers and mentor Mr.Tanay Pratap, I am finally going to switch to JS.

Starting off, I am reading the Eloquent JS , and this is the first blog in a long series of blog posts. I am reading through and learning all the things mentioned in the book, and logging each chapter as a blogpost.

Chapter 1 : Values, Types and Operators

As we are all familiar, all values numbers variables everything is stored in binary form and read and used by the computer, be it the internet , your CPU or the compiler. Hence, binary is all that we will consider our scales in.

Numbers

  • JS uses 64 bits to store the numbers, in the signed format, i.e., the MSB (Most significant bit) will be a 0 or 1 and decide the sign of our number, positive or negative.
  • For large numbers, the scientific notation of e is used.

    • 2.99e8 = 2.99 * 10^8 *JS also allows for 3 special numbers, namely :
    • Infinity : Positive infinity
    • -Infinity : Negative infinity
    • NaN : It stands for Not a number . This kind of numbers are obtained when you end up doing something weird, say a 0/0 , or Infinity - Infinity operation. ####Arithmetic operations
  • JS allows for a total of 5 arithmetic operators :

    • Addition +
    • Subtraction -
    • Multiplication *
    • Division /
    • Modulo operator %
  • All these are carried out in the precedence order, for example, multiplication will be carried out before addition. However, if there are two operators of the same order , the operation will be carried out in a left to right fashion.
    * Tip : Since brackets are allowed here, we can escape the entire precedence by just putting brackets as required.

    Strings

  • JS uses 16 bits to represent each string, i.e., each string can describe upto a total of 2^16 characters. That is a lot !!

  • Each character is described in its ASCII value, for example, 'A' has an ASCII of 65, 'a' has an ASCII of 97, and so on.

  • There are also some special characters involved, like for the new line we use the \n character.

  • JS uses the backslash() operator to define such special characters, which may have some importance. It also by default folds down if there are two backslash() in a row, so both \n and \n will be treated as the same.

  • Template literal : ${} is the template literal. You can use this inside a string and it wont be printed as it is. Rather, its contents will be calculated and then the result will be printed out. If you are familiar with python, this works the exact same as that of a formatted string.

    Operators

    Now time for some operators 😄 . Wont be going into great details, as these are actually self explanatory

  • typeof : Returns the type of your object

  • > : Greater than operator

  • < : Less than operator

  • >=: Greater than equal to operator

  • <= : Less than equal to operator

  • == : Equal to operator

  • != : Not equal

    • Note : Both the equal and not equal operators above (last two) facilitate automatic type conversion in JS. This means that if you compare a string and a number, JS will convert the string to number, compare and then give you the results. If you dont want such type of automatic type conversions , go for the operators below :
  • === : Equal to operator, compares without type conversion

  • !== : not equal operator, compares without type conversion

  • & : Boolean AND operator

  • && : Logical AND operator

  • | : Boolean OR operator

  • || : Logical OR operator

  • a?b:c : Conditional operator. It checks for condition a, and returns b if true else returns c.

Review

I would love your feedback on this guys, and feel free to revert back to me with any recommendations that you have for me. You can also mail me at padb19122000@gmail.com .

Top comments (2)

Collapse
 
eduardonwa profile image
Eduardo Cookie Lifter

Nice Im also on this path, learning JavaScript 🤘😀

Collapse
 
parambhatt profile image
param-19

Ill be posting some more blogs within the next 2-3 days, stay tuned for amazing content ! 😉