12 fundamental things you must know about JavaScript

Kamruzzaman Kamran
3 min readNov 2, 2020
javascript

It is better to start with an overview. JavaScript is a scripting or programming language that allows you to implement complex features on web pages. But JavaScript was never meant to become the cornerstone of modern web development. In fact, the language was created in less than two weeks, with a very different purpose in mind. When JavaScript was created, it initially had another name: “LiveScript”. But Java was very popular at that time, so it was decided that positioning a new language as a “younger brother” of Java would help. But as it evolved, JavaScript became a fully independent language with its own specification called ECMAScript, and now it has no relation to Java at all.

Now, Let’s take a look at some very common yet important programming features of javascript.

Variables: variables in any programming language are used to store data. There are three types of variable in JS: “var”, “let”, & “const”.

  1. “let” has to access only within the block, the declared variable is available from the block it is enclosed in.
  2. “const” variables are declared when the value of the variable will not change.
  3. The “var” is a scope-level variable. It can be accessed from anywhere within the scope.

“If a variable is declared without assigning any value to it, its type is UNDEFINED”

Numbers: Unlike other programming languages, Javascript has not such thing as int.

4. To get the number to an integer, one has to use the built-in function parseInt(). The function parseInt() parses a number or even a string argument and returns an integer value.

5. But wait, the value could be a fraction number something like 1.8 or 0.0000, so how we get the integer value. To solve this issue, There’s also a built-in object called Math that provides the advanced mathematical function and constants. Just use Math.round(1.8) to get the integer 1. Or you can just use Math.ceil() or Math.floor() methods as needed.

Strings: Strings are nothing but a sequence of characters. In javascript, you can use strings like objects also. They have methods as well that allow you to manipulate the string and access information about the string.

6. To find the length of any string, just use theString.length().

7. You can transform any string to uppercase or to lowercase using the theString.toUpperCase() & theString.toLowerCase() methods.

8. The replace method will replace any string or a piece of string with another string. An Example, 'hello world'.replace('world', 'mars'); // "hello mars".

Objects: Objects are used to store keyed collections of various data and more complex entities. In JavaScript, objects penetrate almost every aspect of the language.

9. There are 2 basic ways to declare an empty object:

  • var newObj = new object();
  • var obj = {};

Though they are semantically equivalent, the second one is much convenient. This is also the core of JSON format. There is an object prototype bellow

var person ={

name: ‘ human’,

age: ‘ 25’,

nature:{

color: ‘ brown’,

job: ‘eating’

}

};

10. The value of an object can be accessed in two ways.

  • DOT notation: Example person.nature.color ; // brown
  • Bracket notation: Example person[‘nature’][‘color’] ; // brown

Arrays: An array is used to store a collection of data, but it is often more useful to think of an array as a collection of variables of the same type. In javascript, the array is a special type of object that lets you store multiple values in a single variable.

11. An array can contain every type of data including Numbers, Strings, Objects, or even the Functions.

12. To Find the length of an array, simply use the array.length method. You can get a specific value by specifying the index, for example: array[5]. It will the 6th number value of the array (since the array index start from 0).

There are more array-related methods in Javascript like the .map(), .find(), .filter() etc.

Bonus: You Can Learn more in detail about javascript basics from this MDN article.

That’s it for today. Hope you like this basic informations.

--

--