Fundamentals of JavaScript
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:
- <script> //we can write our code in between the script tag</script>
- <script src=”./script/filename”>We can add external JS file also</script>
Summary:
- We can use a <script> tag to add JS code to a page.
- The “type” and “language” attributes are not required in modern times.
- 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.
- Number -> The number types represent both integer and floating point numbers.
- BigInt -> BigInt is a special numeric type that provides support for integers of arbitrary length.
- String -> A string in JS must be surrounded by quotes.
- Boolean (logical type) -> The boolean type has only two values: true & false.
- Null -> In javaScript null is a special value that represents “nothing”, “empty” or “value unknown”.
- Undefined -> The meaning of undefined is “value not assigned”.
- Symbol -> A symbol is a unique and immutable primitive value. Symbols are also called “atoms”.
- 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”.






