Learn basics of JavaScript (For Absolute Beginners) - Part -1

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
this conference will now be recorded hey guys this is Lavinia if I'll come back and have you know dimension lapse so in this particular video I'm going to teach you JavaScript and it's kind of a crash course kind of thing I'll try to cover some basic important things of JavaScript at least you know like what is JavaScript what do you mean by data types what is object what is array what is how to declare dynamic typing and all those things we will try to cover and then it will be a quick overview about the JavaScript that how to write the basic code in JavaScript and then it's not a full lengthy course but I'm pretty much sure that okay you will be liking it and then you will learn at least something about JavaScript for sure about it so so people who are actually looking for JavaScript if you really want to learn within one or something at least please go through this entire video please watch till the end a lot of new things you will be learning with respect to JavaScript okay know first of all that the question comes here that okay what do you mean by JavaScript so javascript is a programming language right so JavaScript earlier we used to call that okay it is only for browsers that javascript is always executing at the client side at the browser side so let's see if you have multiple browsers are running we have chrome we have Firefox we have Safari right so multiple browsers are running the Java Script is running inside the browser okay so always remember Java Script was earlier is a browser language so whatever the actions are happening on you clicking on a button you are clicking on you're filling the form some user validation some password policy or whatever is coming through JavaScript let's see some alert is coming you click on a pop-up you click on a button pop-up is coming everything is coming from JavaScript over there from the different browser and every browser is having one important thing that is called JavaScript engine so every browser they implement one javascript engine let's see for google chrome we have one javascript engine that is called v8 for fire for it's a separate JavaScript engine for Safari it's a separate JavaScript engine for Internet Explorer it's a separate JavaScript engine and this engine is capable enough to execute your JavaScript code like this right so every engine is programmed in such a way that okay the JavaScript can be executed on a specific browser and this v8 is returned by Google okay it's written by Google obviously it's coming from Google Chrome browser it's written by chromium team and we add is a JavaScript engine available on Google Chrome and then it's written in C++ actually okay and then they use the combination of B that is the JavaScript v8 engine and then on the basis of that they have created node dot J's right now the question is what do you mean by note or Jess also this this particular video is not about a note on chase but just to give you an idea Java Script is the client is the browser language but no not J's is running on your server so this is your server is running either it is your Apache Tomcat or whatever or your node server the node dot J's is running over here the code is running over here sorry not for appertain I'm talking about no 20s so node dot J's is a server written in JavaScript on top of v8 provided by Chrome but it's not like any request is coming from either it's coming from Rome to the node dot J server or from Firefox from Safari or from opera or any kind of browser or any internet explorer browser no dot J server is capable enough to handle any kind of JavaScript request which is coming from the client which is coming from the any kind of browser so that's fine no dot J's is a server side it will be executed at the server side but no JavaScript will be executed over here ok so don't be confused between no dot J's and the JavaScript no dot J's is nothing is just a server work in JavaScript so earlier JavaScript we used to the little you used to tell that oh it's a client-side programming language but after no tortillas after implementing with the v8 it is now server-side programming language reppin ballasting okay so earlier it's it's not being there ok Javas it only works in in the respective browser right but it can be executed on your server also it can handle all your HTTP requests this is just like we are running one Java server or Python server or the Ruby said work like this same thing we have for JavaScript we have no dot JN this server is available fine so this is the basic introduction about JavaScript and everything now the next thing is if you really want to write a JavaScript code so we have to write a couple of basic things so firstly we'll talk about that how to install ok a redditor which okay or which editor you will be using it so we will be using there are different types of editors are available ways you can write your code in sublime also you can write your code in both lists or notepad plus plus also but my favorite is to be a score vs code is V to the studio borage very lightweight very easy very much compatible with JavaScript and it's very fast as compared to ok as compared to other editors you can write your script in IntelliJ as well as in Eclipse also you just need to use a different plug-in for that but I would prefer personally I would prefer BS code for any kind of JavaScript code ok then how to install you simple go to google let's say you go to google and then you simple right download ok Weezer's to do both and you simple download is it's available on Mac Linux and Windows machine so I am NOT going to download please download and start using it it's very straightforward you just need to download it and that's it you just need to use the open source community version for that ok it's free and built on open source integrated with debugging an extension mode so you can simple use it either your 64 bits to bid or Mac machine or Linux machine if you are using it so I'm going to download I'm just directly launching my via score over here directly like this so this is the vs code you can see it over here first time it will show you the value them screen you just close the welcome sting and click on this particular project Explorer or head this is a project exclusive right now first thing is the V is code we will be talking about once again we will be talking about a different and theta H slot so obviously before creating in the pool before writing the code what we need to do that we need to check that okay how exactly JavaScript works on a specific browser because we are saying that okay javascript is a browser language so before starting data types first let's talk about how exactly JavaScript works on a specific browser so let's see I will go to a particular site at any particular site let's say an open google.com a moment I open google.com you right-click on it and go to inspect so as I told you that every browser is having their own JavaScript engine you go to console so this is the console screen you can see it over here and on this particular console this is a JavaScript engine the moment you write any JavaScript code let's see a prediction filled console dot log I sent the right hello like this so hello will be printed I sample right don't worry so hello what will be written I simple say that method alert hey this is testing you see that one alert is coming over here so these methods are coming from JavaScript and then these methods I can execute my JavaScript code over here inside the console okay and this execution is happening through the Chrome browser engine so every browser is having their own engine engine which will support JavaScript so you can directly execute in the browser but this is not a standard way right we need a proper editor we need a proper a tool where we can write the code we can execute we can compile the we can run the pool right so for that we need visible studio put now what we will do in Visual Studio code first we will create a basic folder in my laptop so I will go to my let's see my documents under my documents let's see I will create one folder that JavaScript I think I'll say simple JavaScript basics why even create in C Drive or D Drive wherever you want you can create one folder Java scripts basics or JavaScript basics whatever the name you want to give it doesn't matter and then you just drive this particular project over here in your Visual Studio code like this you simply drag it over him so the moment you drag it automatically you will see that okay this particular folder God created JavaScript basics and automatically it will give you a welcome screen over here now you close this welcome screen after that what you need to do we just open your project and click on this button the new file create a new file and let's see I'm going to create a new file this file name is index dot HTML and the moment you write index dot HTML and then here you can write the script you seem to write : and tab ok so I'll repeat simply write : and davit press tab the moment you click : tab you will see that some basic JavaScript is running over here I mean it's created over here simple HTML Dom you can see over here now what you need to do you need to do is as I told you that the JavaScript will be executed on a particular browser so now I want to see that okay this index dot HTML is running a particular house so what you need to do you need to add a plug-in over here so I need to I need one web server which can so that I can pass this index dot HTML to that particular web server and then I can see whatever I am writing over here and I can see my execution is happening on that particular web server on a specific browser so what you do you simply go to the extension tab over here and then you simple type in life server and just click on this particular plugin you need to add this particular plugin over here so right now I have already installed so you just click on install button and your kiss ok it will be installed but I mean you just click on it and then after that you simple restart your Visual Studio code restart your editor after that when you restart come back to your project Explorer and then simple right click on your index dot HTML and simple select this option open with Lite server and then you click on it ok so it's saying server is started at port number 5500 okay now you do one thing we just go to Google or open your browser and simple right your localhost let's see my IP address of the local host is 127 0.02 1/50 500 and then enter and you will see that ok yes my actual index I mean my actual browser is the server is up and running the web server is up and running over here and then you simply write slash index dot HTML and you will see that index dot HTML is running over here although index dot HTML doesn't have any any element to show case over here but this index dot HTML is perfectly working over here now what I do just to change a yogya my index dot HTML is running but not what I will do I will come inside the body section over here and then I'll write one header so let's see my h1 header and right ok and inside this particular h1 header I'll say something let's see Navi automation laughs and then you simply control a s you save it the moment I say we immediately intervene automation labs will be visible over here in the next line I write something some another header let's see I'll try hello Naveen [Music] something like this and then the moment you press save Amit Italy hello Naveen will be displayed over here right there is something over here and I'm passing my index dot HTML over here so that whatever the content you are writing over here same content TV displayed over here simple like this if you want to write any HTML or CSS the same thing you can write it over here along with your JavaScript code you can write it over here right so simple this is a header h1 h1 I have added but this is one this is your HTML code what if this is not my JavaScript code this is a simple HTML code so what will happen guys I want to add if you really want to add a JavaScript code what you need to do for JavaScript code you need to add a script over here okay you need to add one script tag Orion so generally we add the script once okay inside the body tag remember 99% cases you have to add your script tag inside your body tag you should not add the script inside the head right so you should always use at the end of the body tag once all the elements are declared all the HTML tags are declared after that you have a doing why if you let's see you are writing 10,000 lines of code in JavaScript and you are writing over here before all the elements then first it will execute all the JavaScript and then it will render your elements so better first you render all the elements and then execute your script so how do I write a script using the right script tag over here like this this is the script tag and under this particular script tag what you need to do you need to write a JavaScript script over here let's say writing console console dot log is just like system dot out dot println off print a statement I simple right once well dot log I want to build it hello lovey like this ok and then you say it the moment you save it as I told you that immediately this particular script will be executed on the browser in the console ok so what I'll do I right click on it and go to inspector and gorgonzola right and then what you do you simple save this part in a file and then you should be able to just refresh this particular page you can see Hello Navi is getting printed over here right so let's see I'll write something else I try to write some more things console dot log hello JavaScript just save it immediately hello JavaScript will be printed over here so whatever the script that you were writing over here the same script will be executed on your and so inside the browser and whatever the element that you are defining that these element will be visible on the web page like this okay simple so this is the script that you have written over here and the same script will be executed over here so this is how we have to design the back pages and this is how we have to enter the scripts Java scripts in your HTML file right but again this is not the right way again that okay you are writing 10,000 lines of pour over here so what we need to do that we need to create one more file over here so let's say I am creating one file index dot JSON or jail is your javascript extension you create index dot J's and inside this index dot J's I simply create a script over here like the same script and just copy paste over here this is my JavaScript code console dot log something like this and then you save it now what do you do you simple remove this particular you just comment it out so how will you comment it out to sinful good to /it mean this but Allah put is commended out right right compiler will not execute these lines of code now what do you do simple I'll create our script tag once again so let's read why simple right script tag once again like this and under this is predator script that we have a dent with exactly your source so SRC script SRC m10 you tell my index dot J's and then you run it and then you simple refresh your browser same thing hello Naveen and hello JavaScript is getting printed tomorrow if you write lessee some other okay JavaScript code over here let's yes but right console dot log ice until say let's see 2+2 you save it and you can see 2+2 4 is coming over here you can see inside the console right so my web server is running my HTML pages mashed my attacks are getting displayed over here and I can see my JavaScript code also running over here like this so what exactly I have done in index dot HTML I have given the source dot ok hey pick the JavaScript from here and then simple execute on my browser inside the console through the JavaScript engine through the engine like this same thing as I told you that JavaScript code can be executed by node also so what you need to make sure no dot J's is already installed on your system so if you don't have no dot JSP installed no dot GS so how we install using will go to Google and simply write a download node.js you simple download no dot J's you can download on your Mac machine Windows machine and ok and then simple download I am NOT you download it simple just need to check that ok node is available audio system or not and you go to a terminal on yoga mantra anything simple right no space - - virgin make sure that okay note version is available on your system like this and then what you do you go to your terminal over here okay so in this editor also we have one terminal over here you can go to terminal and then you can execute this particular file the index dot JSP directly from here as well in the moment I write node index dot JSP material giving getting hello Naveen hello JavaScript and two plus two equal to four it means whatever you have written inside index dot J this the same code is getting executed over here so as I told you node is also capable enough to execute your code execute your JavaScript code and if you really want to execute on your browser you can directly execute on your browser as well okay so this is the thing but this is some basic things let's see we have rated so those things node and all those things maybe I can cover it later but now what we have to do i simply create another file over here and simple I'll write JavaScript this is okay simple trying Thomas could be six dot J's file so dot J is extension I close this and I close this as well now first off isn't even talk talk about datatypes so as we know that okay every programming language is having its own types so what I do whatever the code we are writing over here I'm going to check in my browser so what I'll do I take this particular Google Chrome browser and simple let's use it like this and I just shrink it like this okay so that we can see that browser execution is happening over here or not and so that like this let me set up just a second one second let me check okay I'll do one day yeah sorry I'll run that particular 127 indexed on each treatment once again over here right click on it go to inspect go to console and then you will see the JavaScript code should be we should give them output over here and then I do it like this okay so here we will write the code and then here we will see my execution is happening or what okay Pavan yeah so like this you can check it right over here now data types so India dives simple if you really want to define a variable so so the right where but there be used to do earlier now in modern JavaScript we use ill net keyword simple right in that name is equal to whatever the name you want to write so let's go back in the weight and put a semicolon okay you simply write that name is equal to in the beam okay now use the movement you save this particular thing that name is equal to in the beam and what I'll do is I'll go to my index dot HTML instead of index dot JSP right I have to give the path of in JavaScript don't chase JavaScript objects and then you save your JavaScript on J's over here and you simple refresh your browser and let name equal to the V now I want to print something on my console so how do you do it essentially console dot log and then I sent the same name and a moment I write names immediately nothing blueprinted over here and you can see JavaScript is X dot J's line number three right so this is how we can print some variables over here like this first of all the guys you have to remember that the variable name you have to give a proper variable name you cannot use any reserved keyword so let's see what if keyword is there so I cannot write it okay if it is equal to yes no this is not allowed if we give you terror its same unexpected token if because if is the quantity reserved keyword just like two phones offense so you don't need to remember all these keywords make sure that again you should not use any existing reserved keyword now let's see I am declaring age is equal to 25 okay a table what if I and then I want to print name plus some space then plus h so it's same Lavigne anyways so in JavaScript you can write double quotes for the string or you can write single words but generally we use single quotes in the modern JavaScript code okay so simple what we have done we have created these two variables and printing it on the console like this first of all the variable name cannot be started with any number also okay we should always give a meaningful name it should not start with any n number over here and now this conference will now be recorded nowadays what I have does also dot log I have printed like this so similarly you can imprint any variable or you can create any type of variable let's same printing color is equal to red like this and in console dot log you can try it console dot log let see two plus two and the moment you write 2 plus 2 will be 4 but the color and TV color will not displayed why because I'm not printing color over here so console dot log whatever you are I think it will be printed over here okay lines simple now if I write something like this let's see let that simple right range is equal to 4 right and the next line if I write the range is equal to 5 and then I print console dot console dot log and I print the value of range tick means this is a variable a variable means the value will be stored inside the memory and the from memory a location will be given and then the initial value was for now the new value is 5 I have a given so console dot log range so what will be the latest value of range the latest when you have ranges 5 even think 5 is getting printed over here right so this is the variable part what if I want to define some constants so let's see I wandered again no one can change the value of range so instead of let I simple say constant over here so the moment I write constant range equal to 4 immediately it means I cannot change the value of range so that's why it's giving you error assignment to constant variable at line number 9 so now I cannot change the value this is just like final keyboard is available in Java same thing we have to provide the constant over here so now I cannot change the value of rage so now range will all will be for like this simple one more example of constant let's say constant this is the right number of days in a week is all this seven I cannot write it okay a number of days equal to eight if I don't write constant over here I simple write only elected it means now tomorrow anyone can change the value of number of days to eight or ten and my entire calculation will be disturb in that case right so always provide such kind of things with constant variable so be able to use this particular keyword constant keyword right so this is how we have to create the constant evil now you have to remember one thing is that in JavaScript there are four important two types of data types are available the first is and write something over here so the first type of is we have primitive container types so we have four primitive data types one is spin then we have number then we have millions and then we have one more undefined it's a spring number boolean undefined and then the fifth one is none okay not for four types and then the second type is to be the second type is the reference type so reference type can you read them first let's talk about okay let's talk about all these ways the primitive and data types so how to use string so as I told you third string can be used something like this in the light light string s1 is equal to you simple bite hello world put a semicolon once this is done okay and then you can print it let's see I want to create one variable int age is equal to 30 so this is the numeric variable like this int age is equal to 30 because H we have already taken it's giving you an error so let the else in the right int number is equal to 30 then I want to write Betty let some boolean flag is equal to prove like this all right let's see the user is active or not is equal to true or false also you can get lazy user is not active okay like this some variables can be defined like this let's see I'm writing price variable price nothing let price having no values and then somebody where I can define like this I see model is equal to money and some very well also can be defined being an undefined variables also let's see price model and then I sent the right one more variable let's see Wheelz is equal to undefined so undefined is also a value for undefined type it means this means is not defined now these are this is the string and this is the numeric value integer value this is what this is a boolean this is also boolean this is also not defined this is a multiple you and this is undefined now in JavaScript base there is a function you put a concern and then come over here there is a function that is called type of function and then use them to write the type of s1 it's giving the type of s1 is spring equals what is the data type of s1 so the data type of s1 is defined with string in JavaScript now I want to check the type of the type of number the type of number is number always remember this thing the type of number is number tomorrow I can write sum let's see salary is equal to twelve point three three so some decimal number the floating number also I can write it over here but just like in other programming languages like in Java and C in C++ we used to have double n floating keywords over here but here everything is defined with number now if you want to check that what is the type of salary the type of salary is also number so either you're ending integer you are adding double you are adding any floating number everything is defined with number over here so the type of so the type of the variables for integers values for double values for floating values will always be number now I want to check the type of flag the type of flag is boolean the type of I simple say the type of price I'm going to write the type of prices undefined because we have not given any value so undefined this okay a special type of data where the data is not defined now I want to check the type of model now see the type of water is not done even the type of what L is object because object null is presented by object okay so be here to write of type of model is object not done well same thing the type of wheels is also undefined because the value is undefined so undefined will behave like a value also if you write and if you don't try by default price but also be undefined okay so these are the different types of data available over here right now javascript days remember it's a dynamic typing okay dynamic typing what do you mean by this Daniel 8 I think means it doesn't matter that if tomorrow let's see I write and let our D is equal to some strength let's see the V right and next time I sent the right D is equal to 30 right so immediately this is called dynamic typing it's not the static typing but in Java you cannot write because in Java if you write a string D is equal to the mean in double quotes I cannot use for the numeric values but in JavaScript I can use it this is called dynamic typing and the moment you write simple type of B now now the type of B is number but earlier it was declared with the string so this is called dynamic typing a given simple see what okay so remember the value can be changed any kind of value any type of data I can store over here okay doesn't matter initially it declared with string and then later on I am declaring with or some number fine now the second type of is reference type and I told you reference type means simple you have objects then you have arrays and then you have functions these are called for reference types data types okay well let's talk about object back to my vs code let's talk about objects how do you declare an object declare an object you simple just like in Java we have to create a class and then we have to define the class property so same thing for multiple object we can create for the same class same thing in JavaScript you can object is representing a physical entity let's see there is a person so how to create an object for a person simple writing it I simple right let's see a person or a user the user is this is the right is equal to this is called okay an object having and finding ok the object which is undefined undefined properties are there but if you really want to define some property you're super say like this put a semicolon over here and then you sent the right let's see the user properties name : I sent the right something like this let's see name is equal to Tom like this so this is the first property and then I'll write H property H : 30 okay like this and then I want to print it let's see and soil dot log I print the user over here now you see the moment I print console dot tog user what exactly is printing its printing giving you let me run it again refresh it and you simple it's same named on a is equal to 30 named Tom N is equal to 30 and what kind of data it's object and all other different properties it will be shown over there right so named Tom is equal to 30 these this is the user object that I have created okay so this is the syntax for creating the objects in JavaScript named Tom age 13 so in this particular properties are available for here now the cool thing is I want to access these properties so how many X is these properties so there are two ways the first way is simple use or dot notation how do you use dot notation we set the right one so we thought we log and then I want to use in bracket I'm going to use user dot name property so the moment I write user dot name it will give you Tom over here can you see the tom same thing I am going to use user enjoy dot log user dot H ages 30 so user dot H will be simple right user the property name object name dot property name object name dot property name like this okay too I want to change with the user and dot I want to change the age is equal to now 35 so this particular of the property age now got updated from 35 now I will print once again user dot age now in same user dot ages 35 right so it's simple in a more performant dot log I send the right let's see I sent the right user dot name plus on the animated with plus user dot age like this so what is that it's printing wrong then some space 35 okay simple this is here right now the second way is you can use that's not very popular you can use using bracket notation I'll do use bracket notation you simplify it let's see evaluate says what is the object name my object name is user right the object name is user simple try it and then I want to change the name which in name is equal to 1 X 10 right it gets married right and then I want to print sorry I won't break we use a dot name so the night property got updated okay too many now normally it is value of the user dot name is Mary so like this also using bracket notation also ways we can sympathize it over here okay simple now so this is about a using bracket notation and this is about the objects you have to create so I'm not going in a very detailed things over here I'm simple basic covering some basic small things so that quickly we can cover some more topics over now let's talk about arrays in JavaScript how could it really be so array is what area is nothing there's a list of objects just like in other programming which is that any should have really similar type of data arrays are always static in nature and then then we have to create dynamic arrays just like a data store something in Java but here in JavaScript analysts are two arrays are already dynamic and then you can store any kind of data either it is string bullion or whatever that doesn't matter so let's see how to create an array so let's see allocate on Eric else on the right let and then let them create one language array and that whole declared language array is equal to simple right square bracket okay so this is called a blank Eric empty array now I want to fill the data over here I go to fill that and see my language is Java comma in JavaScript like this so any will maintain the order so Java will be at zero position this will be as the first position now I want to bring some value so simple Lachie I'll write console dot log then I want to print let's see the complete language area and then you save it it seemed to same it's printing over here you can see Java in Java Script zero is Java first value in JavaScript like this and the length is equal to two I want to check what exactly the length of the area so send the right console dot log and then you write language dot length method is there while you can see the language dot length is giving you two each line number 49 you can see at line number forty very it's giving you two over here okay so like this let's see I have declared and that is so dynamic in nature tomorrow let's see if you right so let's see this is 0 and this is 1 you simple right language simple right at to the 9 that should be now Ruby like this and then you print control dot log your language once again now this time it's having three values you can see Java sorry Java JavaScript and Ruby writing Java JavaScript and Ruby 0 1 2 so Ruby will be added at the second position at the second number and then again you wanna check the length you can check the length now the current length is 3 now after adding Ruby now the length is 3 no like this also you will do it right if you want to print a specific value so I sent the right console dot log center-right on language and pass the index over here let's and passing language 0 also language 0 what is language 0 long a 0 is Java at line number 55 you can see so Java is getting printed you wanna print one JavaScript is getting better than you to Ruby's getting break it the moment you write 3 over here immediately it will tell you undefined language 3 is not available its undefined but in Java you will get word array index out of bounds exception here you are getting something like this okay so at the runtime times you can simple nap add the value and if you're going beyond the value if we give you any further like this right now if you really want to check that ok if you really want to change the type of language the type of non-buddhists object you can see the type of language is object so it is work and these are also type of object it will store the list of objects so the category it will underline under object political okay so this is the bounds of simple arrays like this so air is we have seen objects we have seen now the last one is what the last one is the function so how to create a basic function parameterize function and how we use our return keyword in a function in JavaScript let's see quickly over here okay now let me write some comedy let's see now we will talk about different types of functions so difficult on jealousy I simply write a function how to create a function simply write a function keyword over here function and give any name give any name so let's see malfunction in is may be some function name achieve the function name is get name function so this is a function name starting with function keyword name of the function and these two parentheses starting body and ending body in function guys we never write semicolon because function is not a statement function is function so we don't write semicolon over here and then inside this function with C and simple writing console dot log and I am printing something I am printing to that [Music] hello like this so if you see the get new function is ready but get name function it's saying hello is not getting printed over here own it's the instead of a lower eye symbol say that this is my function right so it's not printing anything over here console dot log by because we have to all the function so how do you qualify we have to call them function using the right get name is the method name we get name and write the function over here with our cynically and the moment you called cat named function controller we'll come over here if we come inside the spot your function and then we'll print console dot log yeah this is my function and you can see this is my function is getting printed on the inside the central function at C I had created so this is a 0 parameter construction okay sorry 0 parameter function so this is 0 param we are passing 0 parameter okay like this and here we are passing 0 argument and this is 0 parameter now let's create a field where parameter based function how to great so I sent the again by clicking I'll create a function in this part of the function let's see I simple right greet function starting body ending body and inside the spot you agree I simple say that ok this grief will take one name like this and then here I'll write console dot dot long and then I simple same hello plus whatever the name that you are printing hello name right now when I call this potato function I simple same greet and then pass the name o4 here so let's say in passing the mean and then you so it's printing hello Navi over here and if you really want to print over here okay in the terminal is on the right NPM JavaScript basic on Jace you run it center by node JavaScript objects and you see this is function hello nothing is getting printed over here so you can check it over here you can execute with node also not with any balloons on okay fine so this is parametrized function so this is called a parameter and here I am passing for argument in the beam as a string argument here can I use two more function against a simple bike name and age and then I say hello Naveen okay plus then concatenate it with some space plus h and then I pass between the beam over here comma 24 although my edges got 24 days I simple say hello to be 24 is cutting building hey whatever the name number you are you want to bus right now let's see if I'm not passing I will call this particular function once again agreed and then am passing it see this time talk but I am NOT giving the second variable age I am NOT giving any second parameter or second argument as a number age and simple passing Tom so what exactly will print is to printing hello Tom undefined so it will give you undefined for H okay guys if we give you undefined for H simple like this so remember it will give you undefined for H so you can call the function without passing the argument also if you simple pass let's see agreed and then call this particular function it's same simple hello undefined endpoint Eva's only hello name is undefined age is also undefined because you are not just calling it so it will not give you any error over here but it so this is how we can create parameterize based function now how to return or return from a function only return for a function so return from a functionality I simple right one function over here to make a function add function and this function it's saying that okay you give me two numbers number one comma number number two and then here we simple right return keyword and return keyword is used to return from a particular mission here you write simple number one plus number two okay number one plus number two and then I recall this but it a function I'll pass 10 comma 20 so 10 will be given to number 1 when T will be given to number 2 and then it will be returned back 20 plus 20 30 30 will be given to this there so what I do I simple create one more variable it is sum is equal to this and then I will break it and soul dot log and then I'll bring some over here and here you will see the sum is 13 core I can do one thing I can directly write console dot log and then I can directly call this modular function add function passing two parameters for T comma 50 like this and then you see I'm calling for T comma 50 90 we are getting for T will be given to this guy 50 will be given to this guy and then it will return 40 plus 30 90 and then 90 will be returned back like this you can create parameterized function and then you can return from a function as well right then let me help you one more function so the function let's see square root okay give me the square root of a particular simple let's see my number is number okay or if you want to write it like this I sent the write net load is equal to number okay multiplied by number and then you return the route then you return the route and then you call this for your function I simple call this particular function square root with the number so let's say in passing to so square root I am directly printing in the console console dot log pass the square root here so square root we are getting a four over here okay we are getting four same time this part of your function can be called n number of times by possible different values let's see I'm passing 10 so 10 plus 10 100 will be printed over here like this something right so this is how we can return from a particular I'm just giving you the basic idea is how to execute like this how to create a function like this right so that's all for this particular video one more thing you go to your particular console let's see let me maximize it you go to the console we just clear the console and here what if the calculation you want to do whatever you want to write you it's the console dot log and then you print whatever the function directly if you want to print over here what is the function is square root by square root and pass for like this we are getting 16 over here so you can directly okay execute your JavaScript over here make sure the server is up and running now I want to write some calculation to this to give you four I am going to write hundred thousand ten thousand plus two twenty two plus something like this does something like this it will keep adding it will do all the arithmetic operations also here the browser engine is running your Chrome browser engine is running same thing if you want to open in any other browser let's see if you want to open in Safari so I'll go to my Safari and I will create a new window over here let's see and then you simple run this particular server over here and right click on it go to inspect the element and then you go to the console here the console is available over here and you can see all these things are coming over here and you can directly execute your things over here listen writing 2 + 2 2 + 2 I'm getting for able to see that yeah see you can see you just click good before I want to print console dot log and then the square root of 9 do you mean 81 it gives me 81 so as I told you that every programming every browser is having its own JavaScript engine same thing you can do it in your Firefox as well ok so please practice nice simple basic JavaScript I have covered I will try my best to cover as much as possible ok with respect to JavaScript and it will really really help you to work upon some any kind of either you are able to learn no don't change or you want to then any automation tool with respect to like webdriver IO a Cypress product err Tyko it will really help you a lot so at least you will be comfortable with JavaScript so I'll try to add some more interesting stuff with respect to JavaScript but this particular video for the basic knowledge point of view easy be you can practice and then good for you for the beginning point of view ok so that's all for today thank you so much various thanks for watching this particular video if you please like this particular video Pease subscribe to the channel and share this video with others and please press the bell icon over there you can see the break when I can't the right hand side whenever there is a new video automatically you will be can't update solely thanks for watching this is Naveen here from Naveen automation labs and I'll see you in the next video
Info
Channel: Naveen AutomationLabs
Views: 41,020
Rating: undefined out of 5
Keywords: javascript, javascript basics, learn javascript in 1 hr, javascript for beginners, naveenautomationlabs
Id: 62wUFIa-ltw
Channel Id: undefined
Length: 58min 2sec (3482 seconds)
Published: Tue Jan 14 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.