Sitemap
Preeti Sharma

Preeti Sharma

Learning how to code at Masai

Fundamentals of JavaScript

2 min readNov 22, 2023

--

JavaScript, a dynamic and versatile programming language, stands as a cornerstone in the world of web development. Its widespread use and it’s flexibility makes it a must-have tool for making interactive and engaging website globally. Now let’s engage on a journey to explore the fundamental aspects of JavaScript, uncovering the building block that allows us to create dynamic and responsive web applications.

The “script” tag:

JavaScript programs can be inserted almost anywhere into an HTML document using the <script> tag. The <script> tag contains JavaScript code which is automatically executed when the browser processes the tag.

Syntax:

  1. <script> //we can write our code in between the script tag</script>
  2. <script src=”./script/filename”>We can add external JS file also</script>

Summary:

  1. We can use a <script> tag to add JS code to a page.
  2. The “type” and “language” attributes are not required in modern times.
  3. An external file can be inserted with the src attribute.

Code Structure

Statement:- Statement are syntax constructs and commands that perform actions.

Comments:-

One-line comments start with two forward slash characters (//).

Get Preeti Sharma’s stories in your inbox

Join Medium for free to get updates from this writer.

Multiline comments start with a forward slash and asterisk(*) symbol and end with an asterisk and forward slash. ( /* */)

Variables

A variable is a named storage for data. We can use variables to store any kind of data-type. Var, let, and const keywords are used to declare variables.

Data types

A value in javaScript is always of a certain type. There are eight basic datatypes in javaScript.

  1. Number -> The number types represent both integer and floating point numbers.
  2. BigInt -> BigInt is a special numeric type that provides support for integers of arbitrary length.
  3. String -> A string in JS must be surrounded by quotes.
  4. Boolean (logical type) -> The boolean type has only two values: true & false.
  5. Null -> In javaScript null is a special value that represents “nothing”, “empty” or “value unknown”.
  6. Undefined -> The meaning of undefined is “value not assigned”.
  7. Symbol -> A symbol is a unique and immutable primitive value. Symbols are also called “atoms”.
  8. Objects -> The object type is special. It is the only non-primitive type of data type. It is also considered a building block of JavaScript.

Interaction: alert, prompt, confirm

alert: It shows a message and waits for the user to press “OK”.

prompt: The function prompt accepts two arguments. It shows a modal window with a text message, an input field for the visitors, and the buttons OK/Cancel.

Syntax: result=prompt(title,[default]);

confirm: It is similar to an alert It shows a message and waits for the user to press “OK” and “Cancel”. It returns two outputs i.e. “true” and “false”.

--

--

Preeti Sharma
Preeti Sharma

Written by Preeti Sharma

Learning how to code at Masai