
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
10 Interesting things you can do with a few lines of JavaScript
In this tutorial, let us discuss some fascinating things that a few lines of Javascript can do.
Almost every website uses JavaScript. JavaScript was born in 1995, and it is a programming language similar to other languages, but it runs faster because it doesn't have many predefined functions.
JavaScript can create programs, libraries, and scripts for websites or desktop applications. A lot of web developers are also good at writing JavaScript. Some JavaScript codes are fascinating if you observe how it behaves. Let us discuss what are these fascinating things in JavaScript.
Fascinating things about the semicolon
The end of a statement in a programming language contains a semicolon. But, unlike other languages, JavaScript uses a semicolon also to start the code. Do not follow this wrong approach.
;var x = 5
Interesting things about NaN
In JavaScript, anything that isn't a number is also a valid number. An example is "NaN" (Not a number).
Interesting things about Null
A null is an object that represents nothing. If you use the typeof function, you will get information about the null object.
Interesting things about the function
A function can run itself, just like you can do in other programming languages. When you call the below function, it will display "hi" on the screen
(function(){alert(‘hi’);})(); //gives ‘hi’ alert
Interesting things about script tag
Scripts can only have one source file. This file must be in the same directory as the script tag. You cannot include other files or code within the script tag. The following is not possible in JavaScript.
<script src="code.js"> alert("Hi"); </script>
Fascinating things about adding two different types of values
Adding a string with a number gives a string. Adding a number with a string results in a number.
"100" + 2;//prints "1002" 100 + "2";//prints 102 alert("4"/"2"); //2 alert(2 + "3"); //23 alert("4" + 5); //45 alert("8" + 3 + 7); //837 alert(3 + 1 + "5"); // 45
Interesting things about IIFE,
In Immediately Invoked Function Expressions, we can expect different outcomes as follows.
//code runs as it is an assignment var test = function () { //code }(); // Syntax error as it is only a definition function test() { //code }();
Interesting things about undefined
Although "undefined" is a keyword in JavaScript, it doesn't have a specific meaning. Variables can have a special meaning called undefined, or they can be undefined. If a variable is undefined, you can't figure out what it is.
var vb; alert(vb== undefined); //returns true
undefined = "value"; var vr; alert(vr == undefined); //returns false
Interesting things about parenthesis
The parenthesis position will define different functions.
function a() { return { x: '1' } } function b() { return { x: '1' } } console.log(typeof a() === typeof b()); //returns false
Interesting things about numbers
Observe the output for the following.
alert(9999999999999999); //10000000000000000
let x= -0; // -0 let y= 0; // 0
This tutorial discussed some fascinating things that a few lines of JavaScript can do. You will be familiar with all these if you are a JavaScript developer. However, some of these are born bugs.
Without coding, we can do many cool things with JavaScript. JavaScript has had a lot of changes over the years. Make websites that move and make games that you control with your computer. You can also make phone apps and programs that run on your computer without software assistance.
- Related Articles
- What are the things that you can do normally when you are pregnant?
- Interesting Voice-Enabled Internet of Things (IoT) Applications
- What do you mean by Internet of Things (IoT) Gateways?
- 10 Things Your Doctor Won’t Tell You About Hysterectomy
- 10 Interesting Python Cool Tricks
- 10 Things You May (or May Not) Know Cause Skin Cancer
- 10 Things Your Doctor Won\'t Tell You About an MRI
- Can you use Bitcoin to buy things in Retail Market?
- 8 Things You Can Start Doing Now to Look Younger
- 10 Interesting Linux Command Line Tricks and Tips
- How do you get a timestamp in JavaScript?
- How can we measure a curved lines with the help of a divider ?
- With the help of an activity suggest how you can make your magnetic compass. What do you conclude?
- 10 Common Applications of Internet of Things(IoT)
- Do you think a poet can also be a lyricist?
