JavaScript Fundamentals and Core Concepts

Abdul Hannan
4 min readMay 6, 2021

--

JavaScript Fundamentals and Core Concepts

I can see JavaScript everywhere. From beginner to advance websites are built with JavaScript which is almost millions and millions. Nearest future its user experience will broaden day by day. HTML and CSS give the website style on the other side JavaScript makes that website dynamic that means live. JavaScript can use both sides that mean client-side and server-side. So, let's discuss some JavaScript fundamentals and core concepts.

Function:

JavaScript has different types of functions. Let’s discuss them

1. Arrow function:

This function was introduced in ES6. This is the short form of regular function which works almost the same but this function cannot be used in all situations. this function should not be used as like methods and it does not have argument keywords. We can not use the arrow function as constructors. This is also not suitable for the call, apply and bind methods. Example:

const friends = ['kamal','jamal','jashim','rahim'];console.log(friends.map(friend => friend.length));

2. Spread operator:

Spread operators is an ES6 new set of operators. We can copy all objects from the array and then it can expand individual elements by using ( … ) three dots. By using this operator we can make our code shorter and enhances its readability. Example:

function multiply(x, y, z) {return x * y * z;}
const numbers = [2, 2, 3];
console.log(multiply(...numbers));

3. Default parameter:

This is another JavaScript function that can help to set default values for function parameters. The default value which we specify inside the parameter is applied by the compiler. If we don’t use the default parameter inside the function we need to recheck for the existence of the variable. Example:

function multiply(a, b = 3) {return a * b;}console.log(multiply(5));

4. Cross-browser testing:

Cross-browser testing means if you create a website or web apps make sure your website is working on all kinds of web browsers this could desktop browser, mobile browser, or an older model browser. So this is the web developer's responsibility to make sure the project is fit for any type of web browser. Developer must think about some issues like:

· Think about different devices this could be started from a small smartphone, older feature phones that may have browsers, tablets, desktop web browser even bigger smart TV browser.

· People with disabilities, who run the internet with other third-party assistive technologies like screen readers, and some also use the only a keyboard.

· Some older people still using an older web browser which properly does not support CSS and JavaScript.

So, you have to think about all of these. You are a high-end MacBook Pro or iPhone and Nexus Phone user but your user could be the feature phone user. Remember all of them.

5. JavaScript coding Style:

If you are a dedicated JavaScript developer or a programmer you have to think about your coding style and also some rules. Code must be cleaner and easy to readable for another programmer. Good coding practice is the art of a good programmer.

· Give space between parameters

· If give curly brace on the same line give space

· Give space between arguments

· Put space around nested call

· Give empty line between logical blocks

Actually, all of these are not “you must” rules. Don’t make your coding line horizontally too long. Because it is not good coding practice to make lines horizontally long. Example:

if (id === 56 &&bigChicken === 'red' &&smallChicken === 'black') {letEnjoyParty();}

6. Expressions:

If you have too many questions JavaScript can not answer all of them. As if you want to know how much your lover loves you will not get the answer. JavaScript can not help in this situation. Because this is not a JavaScript regular task.

But JavaScript can help you in another way. It understands some special questions so this special question name is expressions. Example:

console.log(2 + 2)

this is the JavaScript expression that means code.

7. Checking a Type:

First time if you see JavaScript code you will thank that all code is the same but you could not differentiate at a glance. So, if you want to check JavaScript value type you need to use typeOf operator. JavaScript will properly answer your values if you type “typeOf”. Here are some basic examples:

console.log(typeof(4));console.log(typeof("hello"));console.log(typeof(undefined));

8. Primitive values:

There are two types of primitive values like numbers and strings. Every Primitive value is common because I can not change anything in my code which will affect them. Example:

console.log(4);console.log("code");console.log(undefined);

9. Block level declarations:

Block means which declarations are not accessible from outside this means if I declare any variable inside the function that can not be called from out of function. ES6 introduced 2 block-level declarations such as “Let Declaration” & “constant Declaration”.

Let declaration as same as Var declaration but the difference is it is blocked in its current code.

Constant variable once declared its value can not be changed.

10. Var declaration:

Var declaration is an old JavaScript variable declaration process. Actually, this is a global variable which means once any variable declared top of the function that can be called outside of the function.

--

--