JavaScript 101 : Part 1

ThrivinHorizon
4 min readMar 28, 2020

--

Oh yeah, Here I am excited to take you on a journey of learning something new everyday. I will be learning myself and you can follow along too. It all started by watching a Ted Talk by “Josh Kaufman” titled “The first 20 hours : How to learn anything” and this with other series will be completely based in learning that way. And I will include all the useful links for learning and all the code that I’ll write will be available to you on GitHub. And yes beginners who have a little or no programming language experience can follow along. This whole journey will be around 3 months covering : JavaScript, HTML & CSS, Git, Linux commands, Gulp.js, Angular JS, React JS, and Node JS.

So why waiting let’s start our first journey(There will be a lot of journeys😉people).

Let’s start with JavaScript

Today we will be covering the following topics: “Introduction to JavaScript”. So let’s start with a Introduction to this amazing evolving scripting language “JavaScript”.

Console

Console is a panel that displays important messages, like errors, for developers. We will be frequently using console to test our code by printing or logging to make things appear on the it. To access our console we will use “console” keyword which gives us access to it. We will the utilize a action or method of our “console” object(for now just remember that objects are just like real world things which have some states and behaviors.) called “log()” method . And we can access that using “.”(dot operator) as “console.log(message)” which will print or log the message we passed it in the parenthesis.

It will be very useful for us to print values to the console, so we can see the work that we’re doing.

console.log("Hello World!");

Note: We don’t need semicolon in JavaScript but it’s just a good way to write your code.

Comments

Comments are a great way to let readers of your code to know how the code works. It’s also a refresher to you see your code after of lot of time. There are completely ignored while interpreting your code.

There are two types of comment in JavaScript:

  1. Single line comment will comment out a single line and is denoted by two forward slashes “//”.
//This is a single line comment

2. Multi-line comment will comment out multiple lines at the same time and is denote by “/*” to begin and “*/” to end the comment.

/* This 
is
a multi-line
comment
*/

Data types

In JavaScript there seven fundamental data types:

  1. Number: Any number, also including decimals.
  2. String: Any grouping of characters inside single (‘…’) or double quotes (“…”).
  3. Boolean: It has two possible values: true and false
  4. Null: Denotes intentional absence of a value
  5. Undefined: Denotes absence of value, but a bit different then Null
  6. Symbol: New feature introduced in JavaScript, I’ll discuss this future. No need to worry now.
  7. Object: More on this later.

Arithmetic Operators

An operator is a character that performs a basic task. And arithmetic operators are the similar operators you have learnt in mathematics to performs calculations on numbers. You can perform addition(+), subtraction(-), division(/), multiplication(*) and remainder(%).

console.log(6 + 6); //Outputs 12
console.log(6 * 6); //Outputs 36
console.log(6 / 6); //Outputs 1
console.log(6 - 6); //Outputs 0
console.log(6 % 5); // Outputs 1

String Concatenation

Some operators have multi behavior also depending on the data type they are used on. One such behavior is shown by “+” operator while operating on string data type. While it adds two or more number but in case of Strings it appends them together and this appending is called concatenation.

console.log("Hello"); // Output: Hello
console.log("Hello" + " " + "World"); // Output: Hello World
//space is also considered a character and appended to other characters.

length property

Properties of objects allows us to perform more complex operations on the data and get useful information from it. One such property for string data types is “length” and is accessed also by “.”(dot operator) and it gives us the number of characters present in the string it’s applied on .

console.log("Hello World"); //Outputs 11 as space is also counted

Methods

These are actions that we can perform and there are lot of built in methods in JavaScript that we can use to see the magic of them. We can also create our own methods but more on that later, first we will utilize those built in function and we will see some methods made for string type.

console.log("hello");//Output: hello
console.log("hello".toUpperCase()); //Output: HELLO
console.log("HELLO".toLowerCase()); // Output: hello
console.log("Hello".startsWith('H')); //Output: true

You can find more on these string methods here: JavaScript String Documentation

So you got the basic introduction to JavaScript and I hope you got the basic know how of the language. I’ll be back tomorrow with “Variables and Conditional Statements”. 😀😀

--

--

ThrivinHorizon
0 Followers

This is the World of ThrivinHorizon, It’s not a destination but it’s a journey to redefine yourself. It will give you the experiences you have never imagined.