JavaScript: Lightweight JS

Devendra Johari
4 min readAug 3, 2023

--

Motivation: I am Learning Full Stack Development. I feel like I should make notes of the topics I learn for making strong my basics. That’s why I made a JavaScript series of notes on multiple topics of JS.

What is JavaScript?

  • Powerful, flexible, and fast programming language.
  • Powers the dynamic behavior on website.
  • Mainly for enhancing the interaction of a user with the webpage.

How can JS modify/add styles to HTML elements?

  • Style of the HTML elements can be modified by accessing them from JavaScript
  • Syntax:
document.object.style.Property-name = “property-value”

Variables

  • JavaScript variables must have unique names. Hence,it is also called identifiers
  • var keyword should only be used at the time of declaration or initialization
  • JavaScript is an untyped language, i.e a variable can hold any data type values

Types:

  • Local Variable -: It can be defined anywhere in the JS code
  • Global Variable -: It will be available only for a particular function where it is defined.

Literals

Literals are fixed values. Before ES6, the strings were created using single quotes (‘) or double quotes (“) and hadvery limited functionality.

In ES6, the strings are created using backtick(`) and gives more control over dynamic strings.

Function of Literals

  1. Multiline string is the ability to span multiple lines.
  2. String formatting is the ability to substitute a part of a string for expression or variable values. ${} syntax expression produces the value. This value can be any computation operations or even a string.
  3. Tagged Template is like function definition, but the only difference is at the time of call there will be no parenthes is () and simply an array of string will be passed as parameter.
  4. String.raw() creates a raw string just like the default function and does string concatenation.
  5. Nested Template allows checking multiple conditions.

JavaScript Operator

1. Arithmetic Operators

2. Relational Operators

3. Bitwise Operators

4. Logical Operators

5. Assignment Operators

6. Ternary Operators

7. TypeOf Operator

JavaScript Data Types

Primitive Data Type

Non-Primitive Data Type

let vs var vs const

let:

  • If we try toRedeclare globalvariables with theletkeyword, we will get asyntax error.
  • After ES6, JavaScript keywords‘let’and‘const’provideblock scope
  • If we declare with ‘let’ keyword, the value of the variables can change.
  • Redeclaring Variables globally and local simultaneously with let keyword won’t impose a problem.

var :

  • We can Redeclare variables with the var keyword.
  • Variables declared with var keyword don’t have block scope.
  • Redeclaring Variables globally and local simultaneously with var keyword will impose a problem.

const :

  • We cannot Redeclare the variables defined with const keyword in the same scope.But, we can redeclare the const keyword variables in another block or scope.
  • We cannot reassign the variables defined with const keyword. It must be assigned at the time of declaration itself.
  • Variables defined with const have Block Scope.
  • Const keyword is mostly used to declare

— New Array

— New Object

— New Function

— New RegExp

--

--

Devendra Johari
Devendra Johari

Written by Devendra Johari

MLOPs Engineer@Giescieve+Devrient, MERN Stack Developer, RedHat Certified

No responses yet