@@ -40,6 +40,9 @@ Top JavaScript interview questions
40
40
| 32 | [ What is strict mode in javaScript] ( #32-what-is-strict-mode-in-javascript ) |
41
41
| 33 | [ What are the different ways to empty an array in javascript] ( #33-what-are-the-different-ways-to-empty-an-array-in-javascript ) |
42
42
| 34 | [ What is NaN in javascript] ( #34-what-is-nan-in-javascript ) |
43
+ | 35 | [ Javascript naming convention] ( #35-javascript-naming-convention ) |
44
+ | 36 | [ Difference between call(), apply() and bind()] ( difference-between-call-apply-and-bind ) |
45
+
43
46
44
47
### 1. What is JavaScript
45
48
* JavaScript is a scripting language used to create dynamic and interactive websites. It is supported by all major web browsers.
@@ -505,6 +508,69 @@ console.log("a"/1) // output ========> NaN
505
508
console .log (Math .sqrt (- 1 )); // output ========> NaN
506
509
console .log (parseInt (" blabla" )); // output ========> NaN
507
510
` ` `
511
+
512
+ ### 35. Javascript naming convention
513
+ 1. Use camelCase (lowercase for the first word, then uppercase for subsequent words) for variable and function names
514
+ 2. Use PascalCase for class names (uppercase for the first letter of each word)
515
+ 3. Use "is" or "has" as prefixes for boolean variables
516
+ 4. Use UPPERCASE for constants
517
+ 5. Use descriptive and meaningful names for your variables, functions, and classes.
518
+
519
+ ` ` ` js
520
+ // variable
521
+ let firstName = " Surbhi" ;
522
+
523
+ // function
524
+ function displayName () {
525
+ return " Surbhi Dighe" ;
526
+ }
527
+ displayName ();
528
+
529
+ // boolean
530
+ let isLoading = false ;
531
+ let hasName = true ;
532
+
533
+ // constants
534
+ let SECONDS = 60 ;
535
+
536
+ // class
537
+ class DisplayName {
538
+ constructor (firstName , lastName ) {
539
+ this .firstName = firstName;
540
+ this .lastName = lastName;
541
+ }
542
+ }
543
+ var name = new DisplayName (' Surbhi' , ' Dighe' );
544
+ ` ` `
545
+
546
+ ### 36. Difference between call(), apply() and bind()
547
+ call(), apply(), and bind() methods are used to attach a function into an object and call the function as if it belonged to that object.
548
+
549
+ **call()** - call() is used to invoke a function immediately with a specified *this* value and allows you to pass the arguments one by one
550
+ ` ` ` js
551
+ let person = {name: ' Surbhi' };
552
+ function printName (message ) {
553
+ console .log (message + ' ' + this .name ); // output ========> "Hello Surbhi"
554
+ }
555
+ printName .call (person, ' Hello' );
556
+ ` ` `
557
+ **apply()** - apply() is used to invoke a function immediately with a specified *this* value and allows you to pass the arguments as an array
558
+ ` ` ` js
559
+ let person = {name: ' Surbhi' };
560
+ function printName (message ) {
561
+ console .log (message + ' ' + this .name ); // output ========> "Hello Surbhi"
562
+ }
563
+ printName .apply (person, [' Hello' ]);
564
+ ` ` `
565
+ **bind()** - bind() returns a new function (which can be invoked anytime), with a specified *this* value and allows you to pass in arguments
566
+ ` ` ` js
567
+ let person = {name: ' Surbhi' };
568
+ function printName (message ) {
569
+ console .log (message + ' ' + this .name ); // output ========> "Hello Surbhi"
570
+ }
571
+ let sayHello = printName .bind (person, " Hello" );
572
+ sayHello ();
573
+ ` ` `
508
574
******************************In progress
509
575
510
576
0 commit comments