CoderFunda
  • Home
  • About us
    • Contact Us
    • Disclaimer
    • Privacy Policy
    • About us
  • Home
  • Php
  • HTML
  • CSS
  • JavaScript
    • JavaScript
    • Jquery
    • JqueryUI
    • Stock
  • SQL
  • Vue.Js
  • Python
  • Wordpress
  • C++
    • C++
    • C
  • Laravel
    • Laravel
      • Overview
      • Namespaces
      • Middleware
      • Routing
      • Configuration
      • Application Structure
      • Installation
    • Overview
  • DBMS
    • DBMS
      • PL/SQL
      • SQLite
      • MongoDB
      • Cassandra
      • MySQL
      • Oracle
      • CouchDB
      • Neo4j
      • DB2
      • Quiz
    • Overview
  • Entertainment
    • TV Series Update
    • Movie Review
    • Movie Review
  • More
    • Vue. Js
    • Php Question
    • Php Interview Question
    • Laravel Interview Question
    • SQL Interview Question
    • IAS Interview Question
    • PCS Interview Question
    • Technology
    • Other
Showing posts with label JavaScript. Show all posts
Showing posts with label JavaScript. Show all posts

31 March, 2022

JavaScript Tutorial

 Programing Coderfunda     March 31, 2022     JavaScript     No comments   

 

Learn JavaScript Tutorial

JavaScript Tutorial

Our JavaScript Tutorial is designed for beginners and professionals both. JavaScript is used to create client-side dynamic pages.

JavaScript is an object-based scripting language which is lightweight and cross-platform.

JavaScript is not a compiled language, but it is a translated language. The JavaScript Translator (embedded in the browser) is responsible for translating the JavaScript code for the web browser.

What is JavaScript

JavaScript (js) is a light-weight object-oriented programming language which is used by several websites for scripting the webpages. It is an interpreted, full-fledged programming language that enables dynamic interactivity on websites when applied to an HTML document. It was introduced in the year 1995 for adding programs to the webpages in the Netscape Navigator browser. Since then, it has been adopted by all other graphical web browsers. With JavaScript, users can build modern web applications to interact directly without reloading the page every time. The traditional website uses js to provide several forms of interactivity and simplicity.


Although, JavaScript has no connectivity with Java programming language. The name was suggested and provided in the times when Java was gaining popularity in the market. In addition to web browsers, databases such as CouchDB and MongoDB uses JavaScript as their scripting and query language.

Features of JavaScript

There are following features of JavaScript:

  1. All popular web browsers support JavaScript as they provide built-in execution environments.
  2. JavaScript follows the syntax and structure of the C programming language. Thus, it is a structured programming language.
  3. JavaScript is a weakly typed language, where certain types are implicitly cast (depending on the operation).
  4. JavaScript is an object-oriented programming language that uses prototypes rather than using classes for inheritance.
  5. It is a light-weighted and interpreted language.
  6. It is a case-sensitive language.
  7. JavaScript is supportable in several operating systems including, Windows, macOS, etc.
  8. It provides good control to the users over the web browsers.

History of JavaScript

In 1993, Mosaic, the first popular web browser, came into existence. In the year 1994, Netscape was founded by Marc Andreessen. He realized that the web needed to become more dynamic. Thus, a 'glue language' was believed to be provided to HTML to make web designing easy for designers and part-time programmers. Consequently, in 1995, the company recruited Brendan Eich intending to implement and embed Scheme programming language to the browser. But, before Brendan could start, the company merged with Sun Microsystems for adding Java into its Navigator so that it could compete with Microsoft over the web technologies and platforms. Now, two languages were there: Java and the scripting language. Further, Netscape decided to give a similar name to the scripting language as Java's. It led to 'Javascript'. Finally, in May 1995, Marc Andreessen coined the first code of Javascript named 'Mocha'. Later, the marketing team replaced the name with 'LiveScript'. But, due to trademark reasons and certain other reasons, in December 1995, the language was finally renamed to 'JavaScript'. From then, JavaScript came into existence.

Application of JavaScript

JavaScript is used to create interactive websites. It is mainly used for:

  • Client-side validation,
  • Dynamic drop-down menus,
  • Displaying date and time,
  • Displaying pop-up windows and dialog boxes (like an alert dialog box, confirm dialog box and prompt dialog box),
  • Displaying clocks etc.

JavaScript Example

  1. <script>  
  2. document.write("Hello JavaScript by JavaScript");  
  3. </script>  
1

A detailed explanation of first JavaScript example is given in next chapter.


JavaScript Index


JavaScript Tutorial

  • JavaScript Introduction
  • JavaScript Example
  • External JavaScript

JavaScript Basics

  • JavaScript Comment
  • JavaScript Variable
  • JavaScript Global Variable
  • JavaScript Data Types
  • JavaScript Operators
  • JavaScript If Statement
  • JavaScript Switch
  • JavaScript Loop
  • JavaScript Function

JavaScript Objects

  • JavaScript Object
  • JavaScript Array
  • JavaScript String
  • JavaScript Date
  • JavaScript Math
  • JavaScript Number
  • JavaScript Boolean
  • JavaScript DataView
  • JavaScript Function
  • JavaScript handler
  • JavaScript JSON
  • JavaScript Number
  • JavaScript Reflect
  • JavaScript RegExp
  • JavaScript Symbol

JavaScript BOM

  • Browser Objects
  • 1) Window Object
  • 2) History Object
  • 3) Navigator Object
  • 4) Screen Object

JavaScript DOM

  • 5) Document Object
  • getElementById
  • getElementsByName
  • getElementsByTagName
  • JavaScript innerHTML property
  • JavaScript innerText property

JavaScript Validation

  • JavaScript form validation
  • JavaScript email validation

JavaScript OOPs

  • JavaScript Class
  • JavaScript Object
  • JavaScript Prototype
  • JavaScript constructor Method
  • JavaScript static Method
  • JavaScript Encapsulation
  • JavaScript Inheritance
  • JavaScript Polymorphism
  • JavaScript Abstraction

JavaScript Cookies

  • JavaScript Cookies
  • Cookie Attributes
  • Cookie with multiple Name
  • Deleting Cookies

JavaScript Events

    HTML/DOM Events

JavaScript Misc

  • JavaScript this Keyword
  • JavaScript Debugging
  • JavaScript Hoisting
  • JavaScript Strict Mode

JavaScript Advance

  • JavaScript TypedArray
  • JavaScript Set
  • JavaScript Map
  • JavaScript WeakSet
  • JavaScript WeakMap

Interview Questions

  • JavaScript Interview Questions

JavaScript Methods

JavaScript Array Object

  • JavaScript Array
  • Array concat() method
  • Array copywithin() method
  • Array every() method
  • Array fill() method
  • Array filter() method
  • Array find() method
  • Array findIndex() method
  • Array forEach() method
  • Array includes() method
  • Array indexOf() method
  • Array join() method
  • Array lastIndexOf() method
  • Array map() method
  • Array pop() method
  • Array push() method
  • Array reverse() method
  • Array shift() method
  • Array slice() method
  • Array sort() method
  • Array splice() method
  • Array unshift() method

JavaScript DataView Object

  • JavaScript DataView
  • DataView getFloat32() method
  • DataView getFloat64() method
  • DataView getInt8() method
  • DataView getInt16() method
  • DataView getInt32() method
  • DataView getUint8() method
  • DataView getUint16() method
  • DataView getUint32() method

JavaScript Function Object

  • JavaScript Function
  • Function apply() method
  • Function bind() method
  • Function call() method
  • Function toString() method

JavaScript Date Object

  • JavaScript Date
  • date getDate() method
  • date getDay() method
  • date getFullYears() method
  • date getHours() method
  • date getMilliseconds() method
  • date getMinutes() method
  • date getMonth() method
  • date getSeconds() method
  • date getUTCDate() method
  • date getUTCDay() method
  • date getUTCFullYears() method
  • date getUTCHours() method
  • date getUTCMinutes() method
  • date getUTCMonth() method
  • date getUTCSeconds() method
  • date setDate() method
  • date setDay() method
  • date setFullYears() method
  • date setHours() method
  • date setMilliseconds() method
  • date setMinutes() method
  • date setMonth() method
  • date setSeconds() method
  • date setUTCDate() method
  • date setUTCDay() method
  • date setUTCFullYears() method
  • date setUTCHours() method
  • date setUTCMilliseconds() method
  • date setUTCMinutes() method
  • date setUTCMonth() method
  • date setUTCSeconds() method
  • date toDateString() method
  • date toISOString() method
  • date toJSON() method
  • date toString() method
  • date toTimeString() method
  • date toUTCString() method
  • date valueOf() method

JavaScript handler Object

  • JavaScript handler
  • handler apply() method
  • handler construct() method
  • handler defineProperty() method
  • handler deleteProperty() method
  • handler get() method
  • handler getOwnPropertyDescriptor() method
  • handler getPrototypeOf() method
  • handler has() method
  • handler isExtensible() method
  • handler ownKeys() method
  • handler preventExtensions() method
  • handler set() method
  • handler setPrototypeOf() method

JavaScript JSON Object

  • JavaScript JSON
  • JSON.parse() method
  • JSON.stringify() method

JavaScript Map Object

  • JavaScript Map
  • Map clear() method
  • Map delete() method
  • Map entries() method
  • Map forEach() method
  • Map get() method
  • Map has() method
  • Map keys() method
  • Map set() method
  • Map values() method

JavaScript Math Object

  • JavaScript Math
  • Math abs() method
  • Math acos() method
  • Math asin() method
  • Math atan() method
  • Math cbrt() method
  • Math ceil() method
  • Math cos() method
  • Math cosh() method
  • Math exp() method
  • Math floor() method
  • Math hypot() method
  • Math log() method
  • Math max() method
  • Math min() method
  • Math pow() method
  • Math random() method
  • Math round() method
  • Math sign() method
  • Math sin() method
  • Math sinh() method
  • Math sqrt() method
  • Math tan() method
  • Math tanh() method
  • Math trunc() method

JavaScript Number Object

  • JavaScript Number
  • Number isFinite() method
  • Number isInteger() method
  • Number parseFloat() method
  • Number parseInt() method
  • Number toExponential() method
  • Number toFixed() method
  • Number toPrecision() method
  • Number toString() method

JavaScript RegExp Object

  • JavaScript RegExp
  • RegExp.exec() method
  • RegExp.test() method
  • RegExp.toString() method

JavaScript Object

  • JavaScript Object
  • Object.assign() method
  • Object.create() method
  • Object.defineProperty() method
  • Object.defineProperties() method
  • Object.entries() method
  • Object.freeze() method
  • getOwnPropertyDescriptor() method
  • getOwnPropertyDescriptors() method
  • getOwnPropertyNames() method
  • getOwnPropertySymbols() method
  • Object.getPrototypeOf() method
  • Object.is() method
  • preventExtensions() method
  • Object.seal() method
  • Object.setPrototypeOf() method
  • Object.values() method

JavaScript Reflect Object

  • JavaScript Reflect
  • Reflect.apply() method
  • Reflect.construct() method
  • Reflect.defineProperty() method
  • Reflect.deleteProperty() method
  • Reflect.get() method
  • getOwnPropertyDescriptor() method
  • Reflect.getPrototypeOf() method
  • Reflect.has() method
  • Reflect.isExtensible() method
  • Reflect.ownKeys() method
  • preventExtensions() method
  • Reflect.set() method
  • Reflect.setPrototypeOf() method

JavaScript Set Object

  • JavaScript Set
  • Set add() method
  • Set clear() method
  • Set delete() method
  • Set entries() method
  • Set forEach() method
  • Set has() method
  • Set values() method

JavaScript String Object

  • String charAt() method
  • String charAt() method
  • String charCodeAt() method
  • String concat() method
  • String indexOf() method
  • String lastIndexOf() method
  • String search() method
  • String match()
  • String replace() method
  • String substr() method
  • String substring() method
  • String slice() method
  • String toLowerCase() method
  • toLocaleLowerCase() method
  • String toUpperCase() method
  • toLocaleUpperCase() method
  • String toString() method
  • String valueOf() method

JavaScript Symbol Object

  • JavaScript Symbol
  • Symbol.for() method
  • Symbol.keyFor() method
  • Symbol.toString() method

Symbol Property

  • Symbol.hasInstance Property
  • isConcatSpreadable Property
  • Symbol.match Property
  • Symbol.prototype Property
  • Symbol.replace Property
  • Symbol.search Property
  • Symbol.split Property
  • Symbol.toStringTag Property
  • Symbol.unscopables Property

JavaScript TypedArray Object

  • JavaScript TypedArray
  • TypedArray copyWithin() method
  • TypedArray entries() method
  • TypedArray every() method
  • TypedArray fill() method
  • TypedArray filter() method
  • TypedArray find() method
  • TypedArray findIndex() method
  • TypedArray forEach() method
  • TypedArray includes() method
  • TypedArray indexof() method
  • TypedArray join() method
  • TypedArray Keys() method
  • TypedArray lastIndexof() method
  • TypedArray map() method
  • TypedArray reduce() method
  • TypedArray reduceRight() method
  • TypedArray reverse() method
  • TypedArray set() method
  • TypedArray Slice() method
  • TypedArray some() method
  • TypedArray sort() method
  • TypedArray subarray() method
  • TypedArray values() method
  • toLocaleString() method
  • TypedArray toString() method

JavaScript WeakMap Object

  • JavaScript WeakMap
  • WeakMap delete() method
  • WeakMap get() method
  • WeakMap has() method
  • WeakMap set() method

JavaScript WeakSet Object

  • JavaScript WeakSet
  • WeakSet add() method
  • WeakSet delete() method
  • WeakSet has() method
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

09 April, 2021

What is JavaScript? | JavaScript Programming

 Programing Coderfunda     April 09, 2021     JavaScript, JavaScript Programming, JavaScript Tutorial     No comments   

What is JavaScript – All You Need To Know About JavaScript


After decades of improvement, JavaScript has become one of the most popular programming languages of all time. It all started in the year 1995 when Brendan Eich created JavaScript in a span of 10 days. Since then, it has seen multiple versions, updates and has grown to the next level. In this blog on what is JavaScript, we will learn the basic concepts of JavaScript.

Here’s a list of topics that I’ll be covering in this blog:

    1.  What is JavaScript
    2.  What can JavaScript do?
    3.  JavaScript Frameworks
    4.  The Big Picture: HTML, CSS & JavaScript
    5.  Benefits of JavaScript
    6.  Fundamentals of JavaScript
      1. Variables
      2. Constants
      3. Data Types
      4. Objects
      5. Arrays
      6. Functions
      7. Conditional statements
      8. Loops
      9. Switch case

What is JavaScript?

JavaScript is a high level, interpreted, programming language used to make web pages more interactive.  

Have you ever thought that your website is missing something? Maybe it’s not engaging enough or it’s not as creative as you want it to be. JavaScript is that missing piece which can be used to enhance web pages, applications, etc to provide a more user-friendly experience.

What is JavaScript?


JavaScript is the language of the web, it is used to make the web look alive by adding motion to it. To be more precise, it’s a programming language that let’s you implement complex and beautiful things/design on web pages. When you notice a web page doing more than just sit there and gawk at you, you can bet that the web page is using JavaScript. 

Feature of JavaScript

  • Scripting language and not Java: In fact, JavaScript has nothing to do with Java. Then why is it called “Java” Script? When JavaScript was first released it was called Mocha, it was later renamed to LiveScript and then to JavaScript when Netscape (founded JavaScript) and Sun did a license agreement. 
  • Object-based scripting language which supports polymorphism, encapsulation and to some extent inheritance as well.
  • Interpreted language: It doesn’t have to be compiled like Java and C which require a compiler.
  • JavaScript runs in a browser: You can run it on Google Chrome, Internet Explorer, Safari, etc. JavaScript can execute not only in the browser but also on the server and any device which has a JavaScript Engine.

 

JS-STATSSS

Currently, we have 100s of programming languages and every day new languages are being created. Among these are few powerful languages that bring about big changes in the market and JavaScript is one of them.

JavaScript has always been on the list of popular programming languages. According to StackOverflow, for the 6th year in a row, JavaScript has remained the most popular and commonly used programming language.

What can JavaScript do?

  • JavaScript is mainly known for creating beautiful web pages & applications. An example of this is Google Maps. If you want to explore a specific map, all you have to do is click and drag with the mouse. And what sort of language could do that? You guessed it! It’s JavaScript.
  • JavaScript can also be used in smart watches. An example of this is the popular smartwatch maker called Pebble. Pebble has created Pebble.js which is a small JavaScript Framework that allows a developer to create an application for the Pebble line of watches in JavaScript.
JavaScript

  • Most popular websites like Google, Facebook, Netflix, Amazon, etc make use of
    JavaScript to build their websites.
  • Among things like mobile applications, digital art, web servers and server applications, JavaScript is also used to make Games. A lot of developers are building small-scale games and apps using JavaScript.

JavaScript Frameworks

One major reason for the popularity of JavaScript is the JavaScript Frameworks. Here’s a brief introduction of the most trending JavaScript frameworks :

1.  AngularJS is Google’s web development framework which provides a set of modern development and design features for rapid application development. 

2.  ReactJS is another top JavaScript framework mainly maintained by Facebook and it’s behind the User Interface of Facebook and Instagram, showing off its efficiency in maintaining such high traffic applications.

JS-frameworks


3.  MeteorJS is mainly used for providing back-end development. Using JavaScript on the back-end to save time and build expertise is one of the major ideas behind Meteor.

4.  jQuery can be used when you want to extend your website and make it more interactive. Companies like Google, WordPress and IBM rely on jQuery.

The Big Picture: HTML, CSS & JavaScript

Anyone familiar with JavaScript knows that it has something to do with HTML and CSS. But what is the relationship between these three? Let me explain this with an analogy.


Think of HTML (HyperText Markup Language) as the skeleton of the web. It is used for displaying the web.

On the other hand, CSS is like our clothes. We put on fashionable clothes to look better. Similarly, the web is quite stylish as well. It uses CSS which stands for Cascading Style Sheets for styling purpose.

Then there is JavaScript which puts life into a web page. Just like how kids move around using the skateboard, the web also motions with the help of JavaScript.

Benefits of JavaScript

There has to be a reason why so many developers love working on JavaScript. Well, there are several benefits of using JavaScript for developing web applications, here’s a few benefits:

 

It’s easy to learn and simple to implement. It is a weak-type programming language unlike the strong-type programming languages like Java and C++, which have strict rules for coding.

 

 

It’s all about being fast in today’s world and since JavaScript is mainly a client-side programming language, it is very fast because any code can run immediately instead of having to contact the server and wait for an answer.

 

 

Rich set of frameworks like AngularJS, ReactJS are used to build web applications and perform different tasks.

 

Builds interactive websites: We all get attracted to beautifully designed websites and JavaScript is the reason behind such attractive websites and applications.

 

 

JavaScript is an interpreted language that does not require a compiler because the web interprets JavaScript. All you need is a browser like Google Chrome or Internet Explorer and you can do all sorts of stuff in the browser.

 

JavaScript is platform independent
JavaScript is platform independent and it is supported by all major browsers like Internet Explorer, Google Chrome, Mozilla Firefox, Safari, etc. 

 

JavaScript Fundamentals

In this What is JavaScript blog, we’ll cover the following basic fundamentals of JavaScript 

      1. Variables
      2. Constants
      3. Data Types
      4. Objects
      5. Arrays
      6. Functions
      7. Conditional statements
      8. Loops
      9. Switch case

Variables  

Variable is a name given to a memory location which acts as a container for storing data temporarily. They are nothing but reserved memory locations to store values.

What is JavaScript - Variables

What is JavaScript – Variables

To declare a variable in JavaScript use the ‘let’ keyword. For example:

1
2
let age;
age=22;

In the above example, I’ve declared a variable ‘age’ by using the ‘let’ keyword and then I’ve stored a value (22) in it. So here a memory location is assigned to the ‘age’ variable and it contains a value i.e. ’22’.

Constants

Constants are fixed values that don’t change during execution time.

To declare a constant in JavaScript use the ‘const’ keyword. For example:

1
2
const mybirthday;
mybirthday='3rd August';

Data types

You can assign different types of values to a variable such as a number or a string. In JavaScript, there are two categories of data types :

What is JavaScript - Data types

What is JavaScript – Data Types

Objects

An object is a standalone entity with properties and types and it is a lot like an object in real life. For example, consider a girl, whose name is Emily, age is 22 and eye-color is brown. In this example the object is the girl and her name, age and eye-color are her properties.

What is JavaScript - Objects example

Course Curriculum

JavaScript and JQuery Essentials Training and Certification

  • Course Duration
  • Real-life Case Studies
  • Assignments
  • Lifetime Access

What is JavaScript – Objects example

Objects are variables too, but they contain many values, so instead of declaring different variables for each property, you can declare an object which stores all these properties.

To declare an object in JavaScript use the ‘let’ keyword and make sure to use curly brackets in such a way that all property-value pairs are defined within the curly brackets. For example:

1
2
3
4
5
let girl= {
name: 'Emily',
age: 22,
eyeColour: 'Brown'
};

In the above example, I’ve declared an object called ‘girl’ and it has 3 properties (name, age, eye colour) with values (Emily, 22, Brown).

Arrays

An array is a data structure that contains a list of elements which store multiple values in a single variable.

For example, let’s consider a scenario where you went shopping to buy art supplies. The list of items you bought can be put into an array.

 

What is JavaScript - Arrays example

What is JavaScript – Arrays example

To declare an array in JavaScript use the ‘let’ keyword with square brackets and all the array elements must be enclosed within them. For example:

1
2
let shopping=[];
shopping=['paintBrush','sprayPaint','waterColours','canvas'];

In the above example I’ve declared an array called ‘shopping’ and I’ve added four elements in it.  

Also, array elements are numbered from zero. For example this is how you access the first array element:

1
shopping[0];

Functions

A function is a block of organised, reusable code that is used to perform single, related action.

Let’s create a function that calculates the product of two numbers.

To declare a function in JavaScript use the ‘function’ keyword. For example:

1
2
3
function product(a, b) {
return a*b;
}

In the above example, I’ve declared a function called ‘product’ and I’ve passed 2 parameters to this function, ‘a’ and ‘b’ which are variables whose product is returned by this function. Now, in order to call a function and pass a value to these parameters you’ll have to follow the below syntax:

1
product(8,2);

In the above code snippet I’m calling the product function with a set of values (8 & 2). These are values of the variables ‘a’ and ‘b’ and they’re called as arguments to the function.

Conditional statements – if

Conditional statement is a set of rules performed if a certain condition is met. The ‘if’ statement is used to execute a block of code, only if the condition specified holds true.

What is JavaScript - if flowchart

What is JavaScript – if flowchart

To declare an if statement in JavaScript use the ‘if’ keyword. The syntax is:

1
2
3
if(condition) {
statement;
}

Now let’s look at an example:

1
2
3
4
let numbers=[1,2,1,2,3,2,3,1];
if(numbers[0]==numbers[2]) {
console.log('Correct!');
}

In the above example I’ve defined an array of numbers and then I’ve defined an if block. Within this block is a condition and a statement. The condition is ‘(numbers[0]==numbers[2])’ and the statement is ‘console.log(‘Correct!’)’. If the condition is met, only then the statement will be executed.

Conditional statements- Else if

Else statement is used to execute a block of code if the same condition is false.

What is JavaScript - Else-if flowchart

What is JavaScript – Else-if flowchart

The syntax is:

F

1
2
3
4
5
6
if(condition) {
statement a;
}
else (condition) {
statement b;
}

Now let’s look at an example:

1
2
3
4
5
6
7
let numbers=[1,2,1,2,3,2,3,1];
if(numbers[0]==numbers[4] {
console.log("Correct!");
}
else {
console.log("Wrong, please try again");
}

In the above example, I’ve defined an if block as well as an else block. So if the conditions within the if block holds false then the else block gets executed. Try this for yourself and see what you get!

Loops 

Loops are used to repeat a specific block until some end condition is met. There are three categories of loops in JavaScript :

  1. while loop
  2. do while loop
  3. for loop

While loop

While the condition is true, the code within the loop is executed. 

What is JavaScript - while loop flowchart

What is JavaScript – while loop flowchart

The syntax is:

1
2
3
while(condition) {
loop code;
}

Now let’s look at an example:

1
2
3
4
5
let i=0;
while(i < 5) {
console.log("The number is " +i);
i++;
}

In the above example, I’ve defined a while loop wherein I’ve set a condition. As long as the condition holds true, the while loop is executed. Try this for yourself and see what you get!

Do while loop

This loop will first execute the code, then check the condition and while the condition holds true, execute repeatedly.

What is JavaScript - Do while loop flowchart

What is JavaScript – Do while loop flowchart

Refer the syntax to better understand it:

1
2
3
do {
loop code;
} while(condition);

This loop executes the code block once before checking if the condition is true, then it will repeat the loop as long as the condition holds true.

Now let’s look at an example:

1
2
3
4
5
do {
console.log("The number is " +i);
i++;
}
while(i > 5);

The above code is similar to the while loop code except, the code block within the do loop is first executed and only then the condition within the while loop is checked. If the condition holds true then the do loop is executed again.

For loop

The for loop repeatedly executes the loop code while a given condition is TRUE. It tests the condition before executing the loop body.

for loop


What is JavaScript – for loop flowchart

The syntax is:

1
2
3
for(begin; condition; step) {
loop code;
}

In the above syntax:

  • begin statement is executed one time before the execution of the loop code
  • condition defines the condition for executing the loop code
  • step statement is executed every time after the code block has been executed 

For example:

1
2
3
for (i=0;i<5;i++) {
console.log("The number is " +i);
}

In the above example, I’ve defined a for loop within which I’ve defined the begin, condition and step statements. The begin statement is that ‘i=0’. After executing the begin statement the code within the for loop is executed one time. Next, the condition is checked, if ‘i<5’ then, the code within the loop is executed. After this, the last step statement (i++) is executed. Try this and see what you get!

Switch Case

The switch statement is used to perform different actions based on different conditions.

switch


What is JavaScript – Switch case flowchart

www.CoderFunda.blogspot.com

1
2
3
4
5
6
7
8
9
10
11
switch(expression) {
case 1:
code block 1
break;
case 2:
code block 2
break;
default:
code block 3
break;
}

How does it work?

  • Switch expression gets evaluated once
  • Value of the expression is compared with the values of each case
  • If there is a match, the associated block of code is executed

Let’s try this with an example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
let games='football';
switch(games) {
case "throwball":
console.log("I dislike throwball!");
break;
case "football":
console.log("I love football!");
break;
case "cricket":
console.log("I'm a huge cricket fan!");
break;
default:
console.log("I like other games");
break;
}

In the above example the switch expression is ‘games’ and the value of games is ‘football’. The value of ‘games’ is compared with the value of each case. In this example it is compared to ‘throwball’, ‘cricket’ and ‘football’. The value of ‘games’ matches with the case ‘football’, therefore the code within the ‘football’ case is executed. Try this for yourself and see what you get!

With this, we come to the end of this blog. I hope you found this blog informative and I hope you have a basic understanding of JavaScript. In my next blog on JavaScript I’ll be covering in-depth concepts, so stay tuned.

Also, check out our video on JavaScript Fundamentals if you want to get started as soon as possible and don’t forget to leave a comment if you have any doubt and also, let us know whether you’d want us to create more content on JavaScript. We are listening!


Resources by: edureka
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
Older Posts Home

Meta

Popular Posts

  • Write API Integrations in Laravel and PHP Projects with Saloon
    Write API Integrations in Laravel and PHP Projects with Saloon Saloon  is a Laravel/PHP package that allows you to write your API integratio...
  • Credit card validation in laravel
      Validation rules for credit card using laravel-validation-rules/credit-card package in laravel Install package laravel-validation-rules/cr...
  • iOS 17 Force Screen Rotation not working on iPAD only
    I have followed all the links on Google and StackOverFlow, unfortunately, I could not find any reliable solution Specifically for iPad devic...
  • C++ in Hindi Introduction
    C ++ का परिचय C ++ एक ऑब्जेक्ट ओरिएंटेड प्रोग्रामिंग लैंग्वेज है। C ++ को Bjarne Stroustrup द्वारा विकसित किया गया था। C ++ में आने से पह...
  • Send message via CANBus
    After some years developing for mobile devices, I've started developing for embedded devices, and I'm finding a new problem now. Th...

Categories

  • Ajax (26)
  • Bootstrap (30)
  • DBMS (42)
  • HTML (12)
  • HTML5 (45)
  • JavaScript (10)
  • Jquery (34)
  • Jquery UI (2)
  • JqueryUI (32)
  • Laravel (1017)
  • Laravel Tutorials (23)
  • Laravel-Question (6)
  • Magento (9)
  • Magento 2 (95)
  • MariaDB (1)
  • MySql Tutorial (2)
  • PHP-Interview-Questions (3)
  • Php Question (13)
  • Python (36)
  • RDBMS (13)
  • SQL Tutorial (79)
  • Vue.js Tutorial (68)
  • Wordpress (150)
  • Wordpress Theme (3)
  • codeigniter (108)
  • oops (4)
  • php (853)

Social Media Links

  • Follow on Twitter
  • Like on Facebook
  • Subscribe on Youtube
  • Follow on Instagram

Pages

  • Home
  • Contact Us
  • Privacy Policy
  • About us

Blog Archive

  • September (100)
  • August (50)
  • July (56)
  • June (46)
  • May (59)
  • April (50)
  • March (60)
  • February (42)
  • January (53)
  • December (58)
  • November (61)
  • October (39)
  • September (36)
  • August (36)
  • July (34)
  • June (34)
  • May (36)
  • April (29)
  • March (82)
  • February (1)
  • January (8)
  • December (14)
  • November (41)
  • October (13)
  • September (5)
  • August (48)
  • July (9)
  • June (6)
  • May (119)
  • April (259)
  • March (122)
  • February (368)
  • January (33)
  • October (2)
  • July (11)
  • June (29)
  • May (25)
  • April (168)
  • March (93)
  • February (60)
  • January (28)
  • December (195)
  • November (24)
  • October (40)
  • September (55)
  • August (6)
  • July (48)
  • May (2)
  • January (2)
  • July (6)
  • June (6)
  • February (17)
  • January (69)
  • December (122)
  • November (56)
  • October (92)
  • September (76)
  • August (6)

Loading...

Laravel News

Loading...

Copyright © CoderFunda | Powered by Blogger
Design by Coderfunda | Blogger Theme by Coderfunda | Distributed By Coderfunda