• Home
  • ES6
  • ADVANCED
    • Javascript Array Methods
    • Javascript String Methods
    • Javascript Regex
    • ES Next
  • JS BOM
  • JS DOM
  • WEB API
  • SNIPPETS
  • TYPESCRIPT
  • Golang
  • Dark Mode Light Mode
  • » Javascript Fundamental. » What is JavaScript
    <h1 id="what-is-javascript">What is JavaScript</h1> <p>JavaScript is a programming language initially designed to interact with elements of web pages. In web browsers, JavaScript consists of three main parts:</p> <ul> <li>ECMAScript provides the core functionality.</li> <li>The <a href="https://www.javascripttutorial.net/javascript-dom/">Document Object Model (DOM)</a> provides interfaces for interacting with elements on web pages</li> <li>The <a href="https://www.javascripttutorial.net/javascript-bom/">Browser Object Model (BOM)</a> provides the browser API for interacting with the web browser.</li> </ul> <p>JavaScript allows you to add interactivity to a web page. Typically, you use JavaScript with HTML and CSS to enhance a web page’s functionality, such as <a href="https://www.javascripttutorial.net/javascript-dom/javascript-form-validation/">validating forms</a>, creating interactive maps, and displaying animated charts.</p> <p>When a web page is loaded, i.e., after HTML and CSS have been downloaded, the JavaScript engine in the web browser executes the JavaScript code. The JavaScript code then modifies the HTML and CSS to update the user interface dynamically.</p> <p>The JavaScript engine is a program that executes JavaScript code. In the beginning, JavaScript engines were implemented as interpreters.</p> <p>However, modern JavaScript engines are typically implemented as just-in-time compilers that compile JavaScript code to bytecode for improved performance.</p> <h2 id="client-side-vs-server-side-javascript">Client-side vs. Server-side JavaScript</h2> <p>When JavaScript is used on a web page, it is executed in web browsers. In this case, JavaScript works as a client-side language.</p> <p>JavaScript can run on both web browsers and servers. A popular JavaScript server-side environment is <a href="https://www.javascripttutorial.net/nodejs-tutorial/">Node.js</a>. Unlike client-side JavaScript, server-side JavaScript executes on the server that allows you to access databases, file systems, etc.</p> <h2 id="javascript-history">JavaScript History</h2> <p>In 1995, JavaScript was created by a Netscape developer named <a href="https://en.wikipedia.org/wiki/Brendan_Eich">Brendan Eich</a>. First, its name was Mocha. And then, its name was changed to LiveScript.</p> <p>Netscape decided to change LiveScript to JavaScript to leverage Java’s fame, which was popular. The decision was made just before Netscape released its web browser product Netscape Navigator 2. As a result, JavaScript entered version 1.0.</p> <p>Netscape released JavaScript 1.1 in Netscape Navigator 3. In the meantime, Microsoft introduced a web browser product called the <a href="https://en.wikipedia.org/wiki/Internet_Explorer">Internet Explorer</a> 3 (IE 3), which competed with Netscape. However, IE came with its own JavaScript implementation called <a href="https://en.wikipedia.org/wiki/JScript">JScript</a>. Microsoft used the name JScript to avoid possible license issues with Netscape.</p> <p>Hence, two different JavaScript versions were in the market:</p> <ul> <li>JavaScript in Netscape Navigator</li> <li>JScript in Internet Explorer.</li> </ul> <p>JavaScript had no standards that governed its syntax and features. And the community decided that it was time to standardize the language.</p> <p>In 1997, JavaScript 1.1 was submitted to the <a href="https://www.ecma-international.org/">European Computer Manufacturers Association</a> (ECMA) as a proposal. <a href="https://www.ecma-international.org/memento/tc39-m.htm">Technical Committee #39</a> (TC39) was assigned to standardize the language to make it a general-purpose, cross-platform, and vendor-neutral scripting language.</p> <p>TC39 came up with ECMA-262, a standard for defining a new scripting language named ECMAScript (often pronounced Ek-ma-script).</p> <p>After that, the International Organization for Standardization and International Electrotechnical Commissions (ISO/IEC) adopted ECMAScript (ISO/IEC-16262).</p> <h2 id="javascript-overview">JavaScript overview</h2> <p>To <a href="https://www.javascripttutorial.net/javascript-variables/">define a variable</a> in JavaScript, you use <code>var</code> keyword. For example:</p> <pre><code class="hljs language-js"><span class="hljs-keyword">var</span> x = <span class="hljs-number">10</span>; <span class="hljs-keyword">var</span> y = <span class="hljs-number">20</span>;<span class="hljs-title class_">Code</span> <span class="hljs-attr">language</span>: <span class="hljs-title class_">JavaScript</span> (javascript) </code></pre> <p>ES6 added a new way to declare a variable with the <code>let</code> keyword:</p> <pre><code class="hljs language-js"><span class="hljs-keyword">let</span> x = <span class="hljs-number">10</span>; <span class="hljs-keyword">let</span> y = <span class="hljs-number">20</span>;<span class="hljs-title class_">Code</span> <span class="hljs-attr">language</span>: <span class="hljs-title class_">JavaScript</span> (javascript) </code></pre> <p>There are differences between <a href="https://www.javascripttutorial.net/es6/difference-between-var-and-let/"><code>var</code> and <code>let</code></a>. And it’s a good practice to use the <code>let</code> keyword to declare variables.</p> <p>To declare a <a href="https://www.javascripttutorial.net/javascript-function/">function</a>, you use the <code>function</code> keyword. The following example defines a function that calculates the sum of two arguments:</p> <pre><code class="hljs language-js"><span class="hljs-keyword">function</span> <span class="hljs-title function_">add</span>(<span class="hljs-params"> a, b </span>) { <span class="hljs-keyword">return</span> a + b; }<span class="hljs-title class_">Code</span> <span class="hljs-attr">language</span>: <span class="hljs-title class_">JavaScript</span> (javascript) </code></pre> <p>To call the <code>add()</code> function, you use the following syntax:</p> <pre><code class="hljs language-js"><span class="hljs-keyword">let</span> result = <span class="hljs-title function_">add</span>(x, y);<span class="hljs-title class_">Code</span> <span class="hljs-attr">language</span>: <span class="hljs-title class_">JavaScript</span> (javascript) </code></pre> <p>To log the result into the console window of the web browser, you use the <code>console.log()</code> :</p> <pre><code class="hljs language-js"><span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(result); <span class="hljs-title class_">Code</span> <span class="hljs-attr">language</span>: <span class="hljs-title class_">JavaScript</span> (javascript) </code></pre> <p>Now, you should see <code>30</code> in the console window.</p> <p>JavaScript provides you with condition statements such as <a href="https://www.javascripttutorial.net/javascript-if-else/"><code>if-else</code></a> and <a href="https://www.javascripttutorial.net/javascript-switch-case/"><code>switch</code></a> statements. For example:</p> <pre><code class="hljs language-js"><span class="hljs-keyword">let</span> a = <span class="hljs-number">20</span>, b = <span class="hljs-number">30</span>; <span class="hljs-keyword">function</span> <span class="hljs-title function_">divide</span>(<span class="hljs-params">a, b</span>) { <span class="hljs-keyword">if</span>(b == <span class="hljs-number">0</span>) { <span class="hljs-keyword">throw</span> <span class="hljs-string">&#x27;Division by zero&#x27;</span>; } <span class="hljs-keyword">return</span> a / b; }<span class="hljs-title class_">Code</span> <span class="hljs-attr">language</span>: <span class="hljs-title class_">JavaScript</span> (javascript) </code></pre> <p>In the <code>divide()</code> function, we check whether the de-numerator (b) is zero. If yes, we <a href="https://www.javascripttutorial.net/javascript-try-catch/">throw an exception</a>. Otherwise, we return the result of a / b.</p> <p>To declare an <a href="https://www.javascripttutorial.net/javascript-array/">array</a>, you use the following syntax:</p> <pre><code class="hljs language-js"><span class="hljs-keyword">let</span> items = [];<span class="hljs-title class_">Code</span> <span class="hljs-attr">language</span>: <span class="hljs-title class_">JavaScript</span> (javascript) </code></pre> <p>To declare an array with some initial elements, you specify the elements in the square brackets:</p> <pre><code class="hljs language-js"><span class="hljs-keyword">let</span> items = [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>];<span class="hljs-title class_">Code</span> <span class="hljs-attr">language</span>: <span class="hljs-title class_">JavaScript</span> (javascript) </code></pre> <p>You can access the number of elements in the <code>items</code> array through its <code>length</code> property:</p> <pre><code class="hljs language-js"><span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(items.<span class="hljs-property">length</span>); <span class="hljs-comment">// 3Code language: JavaScript (javascript)</span> </code></pre> <p>To iterate over the elements of the <code>items</code> array, you use the <a href="https://www.javascripttutorial.net/javascript-for-loop/"><code>for</code></a> loop statement as follows:</p> <pre><code class="hljs language-js"><span class="hljs-keyword">for</span>(<span class="hljs-keyword">let</span> i = <span class="hljs-number">0</span>; i &lt; items.<span class="hljs-property">length</span>; i++) { <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(items[i]); }<span class="hljs-title class_">Code</span> <span class="hljs-attr">language</span>: <span class="hljs-title class_">JavaScript</span> (javascript) </code></pre> <p>Or use the <code>for...of</code> loop in <a href="https://www.javascripttutorial.net/es6/">ES6</a>:</p> <pre><code class="hljs language-js"><span class="hljs-keyword">for</span>(<span class="hljs-keyword">let</span> item <span class="hljs-keyword">of</span> items) { <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(item); }<span class="hljs-title class_">Code</span> <span class="hljs-attr">language</span>: <span class="hljs-title class_">JavaScript</span> (javascript) </code></pre> <p>JavaScript is an evolving language. It has many other features that you’ll learn in the following tutorials.</p> <p>In this tutorial, you learned what JavaScript is and the overview of the JavaScript language.</p>

    GETTING STARTED

  • What is JavaScript
  • Install a JavaScript Code Editor
  • Meet the Console Tab of Devtools
  • JavaScript Hello World
  • JAVASCRIPT FUNDAMENTALS

  • Syntax
  • Variables
  • Data Types
  • Number
  • Numeric Separator
  • Octal and Binary Literals
  • Boolean
  • String
  • Object
  • Primitive vs. Reference Values
  • Array
  • JAVASCRIPT OPERATORS

  • Arithmetic Operators
  • Remainder Operator
  • Assignment Operators
  • Unary Operators
  • Comparison Operators
  • Logical Operators
  • Logical Assignment Operators
  • Nullish Coalescing Operator
  • Exponentiation Operator
  • CONTROL FLOW

  • if
  • if else
  • if else if
  • Ternary Operator (:?)
  • switch case
  • while
  • do while
  • for
  • break
  • continue
  • Comma Operator
  • JAVASCRIPT FUNCTIONS

  • Functions
  • Functions are First-Class Citizens
  • Anonymous Functions
  • Understanding Pass-By-Value in JavaScript
  • Recursive Functions
  • Default Parameters
  • JAVASCRIPT OBJECTS

  • Object Methods
  • Constructor Functions
  • Prototype
  • Constructor/Prototype Pattern
  • Prototypal Inheritance
  • this
  • globalThis
  • Object Properties
  • for…in Loop
  • Enumerable Properties
  • Own Properties
  • Object.values()
  • Object.entries()
  • Object.is()
  • Factory Functions
  • Object Destructuring
  • Optional Chaining Operator
  • Object Literal Syntax Extensions
  • CLASSES

  • Class
  • Getters & Setters
  • Class Expressions
  • Computed Properties
  • Inheritance
  • new.target
  • Static Methods
  • Static Properties
  • Private Fields
  • Private Methods
  • instanceof Operator
  • ADVANCED FUNCTIONS

  • Function Type
  • The call() Method
  • The apply() method
  • The bind() Method
  • Closures
  • Immediately Invoked Function Expression (IIFE)
  • Returning Multiple Values
  • Arrow Functions
  • Arrow Functions: Do & Don’t
  • Rest Parameters
  • Callback
  • PROMISES & ASYNC/AWAIT

  • Promises
  • Promise Chaining
  • Promise.all()
  • Promise.race()
  • Promise.any()
  • Promise.allSettled()
  • Promise.prototype.finally()
  • Promise Error Handling
  • async/await
  • JAVASCRIPT RUNTIME

  • Execution Context
  • Call Stack
  • Event Loop
  • Hoisting
  • Variable Scopes
  • About Me

    • Made by Rasel Mahmud
    • Portfolio

    Top References

    • javascripttutorial.net
    • W3school.com

    Top Tutorials

    • Primitive vs. Reference Values
    • What is JavaScript

    NOTE:

    This website only for Developing purpose not for business. and all content copied from other place like javascripttutorial.net and W3school.com