DEV Community

Cover image for Introduction to Modern Javascript 101
Marriane Akeyo
Marriane Akeyo

Posted on • Edited on

Introduction to Modern Javascript 101

Javascript is a lightweight programming language which is dynamically typed.Some of the key benefits of learning javascript include:

  • JavaScript usage has now extended to mobile app development, desktop app development, and game development. This opens many opportunities for you as Javascript Programmer.

  • Javascript is everywhere, it comes installed on every modern web browser and so to learn Javascript you really do not need any special environment setup. For example Chrome, Mozilla Firefox , Safari and every browser you know as of today, supports Javascript.

  • Great thing about Javascript is that you will find tons of frameworks and Libraries already developed which can be used directly in your software development to reduce your time to market.

  • Javascript is the most popular programming language in the world and that makes it a programmer’s great choice. Once you learnt Javascript, it helps you developing great front-end as well as back-end softwares using different Javascript based frameworks like jQuery, Node.JS etc.

  • Javascript is everywhere, it comes installed on every modern web browser and so to learn Javascript you really do not need any special environment setup. For example Chrome, Mozilla Firefox , Safari and every browser you know as of today, supports Javascript.
    Let us now look at a simple hello world code

console.log("Hello world")
Enter fullscreen mode Exit fullscreen mode

How simple is that right...
Javascript mostly uses the console as noticed from the code above.We are now going to look at the syntax that will enable us write usefull and appealing codes in javascript.
So in javascript one can declare a const which means it is a constant value and thus cannot be changed ,a var which means the value declared is a variable and can be changed or a let which means reassigning of the value is possible.

data types.
In simple terms they explain or demonstrate the type of data being stored.Javascript supports the following datatypes:

  • NULL which includes an object without any value.

  • undefined which includes a variable or constant with no value.eg:

var m;
Enter fullscreen mode Exit fullscreen mode

so when we say :

typeof(m);
Enter fullscreen mode Exit fullscreen mode

then, we shall get undefined. Since javascript is a dynamically typed language you do not need to define other datatypes like strings and numbers ,once you write them , the compiler will automatically understand.
However you can convert from one datatype to another, eg: string() to convert to string and parseInt() to convert to int.

Boolean
Unlike in other languages like python, the boolean values are declared using small letters in javascript.ie true or false.

Conditional Statements
Javascript supports conditional statements like if else eg

if (x<3)
{
console.log (true)
}else{
console.log(false)
}
Enter fullscreen mode Exit fullscreen mode

NOTE
Double equals (==) in javascript are use to show equality of values.(===) are used to check the type of values wherease (=) is used during assignment of values.

Logical Operators
Javascript makes use of the &&(and ) and ||(or) operators as better illustrated bellow.

if (x<3 && y<10)
{
console.log (true)
}
elseif(z==8 || w<10)
{
console.log(true)
}
else{
console.log(false)
}
Enter fullscreen mode Exit fullscreen mode

Functions
We can declare functions in javascript using two diffrent ways:

function (name)
{
console.log(`Hello ${name}`)
}
Enter fullscreen mode Exit fullscreen mode

NOTE the above function accepts parameters.
The other way is using the arrow key function.

username = () =>
{
console.log(`Hello ${name}`}
}
Enter fullscreen mode Exit fullscreen mode

Operators
Javascript supports all the common operators ie +,-,*,/,increment(++) and decrement(--).eg

var num = 0
while (num < 10)
{
console.log(num);
num++;
}
Enter fullscreen mode Exit fullscreen mode

Extra
You might be wondering ...when do I use var,let or even const when writing your javascript code. I would advise you use const when you don't want your values to be changed. Use var when working with the global scope and finally, use let when you are referring only to the block scope .

I hope you got some insight on the modern javascript.
Thank you and happy coding!!!

Top comments (0)